From 93c48dd90c3ae976b997b3a776a3775167b42369 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 2 Jan 2014 15:54:37 +0100 Subject: [PATCH] tests/client.c: Sync with connection.c. --- tests/client.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/client.c b/tests/client.c index 798c5cb..4995536 100644 --- a/tests/client.c +++ b/tests/client.c @@ -20,7 +20,9 @@ #include #include +#include #include +#include #include #include #include @@ -98,7 +100,7 @@ int main (int argc, char *argv[]) { } fprintf(fd_write, "\r\n"); fflush(fd_write); - if (read_http_request(fd_read, buffer, sizeof(buffer)) == -1) { + if (read_http_request(fd_read, buffer, sizeof(buffer)) != 0) { fprintf(stderr, "invalid proxy response\n"); return EXIT_FAILURE; } @@ -271,6 +273,7 @@ static int connect_to_host(const char *hostname, const char *port) { static int read_http_request(FILE *client_fd, char *request, size_t length) { char buffer[MAX_REQUEST_LINE]; + assert(length <= INT_MAX); if (fgets(request, (int)length, client_fd) == NULL) { if (ferror(client_fd)) { perror("read_http_request(): fgets()"); @@ -289,6 +292,8 @@ static int read_http_request(FILE *client_fd, char *request, size_t length) { if (ferror(client_fd)) { perror("read_http_request(): fgets()"); return -1; + } else if (feof(client_fd)) { + return -2; } return 0; -- 2.43.2