X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=tests%2Fclient.c;h=9f9a53f5289a0d40bedcae79695a2508852f4f34;hb=bd777dc79c31027a117df0e334d047504519db08;hp=798c5cbdc3ff4aaf3fcde75fe6756d5a5b9e7a4f;hpb=1af69c9609af41165498e7a1bfda3f32744f12fe;p=tlsproxy%2Ftlsproxy.git diff --git a/tests/client.c b/tests/client.c index 798c5cb..9f9a53f 100644 --- a/tests/client.c +++ b/tests/client.c @@ -1,7 +1,7 @@ /* * Simple GnuTLS client used for testing. * - * Copyright (C) 2011-2013 Simon Ruderich + * Copyright (C) 2011-2014 Simon Ruderich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,9 @@ #include #include +#include #include +#include #include #include #include @@ -63,7 +65,10 @@ int main (int argc, char *argv[]) { if (argc != 5 && argc != 6) { fprintf(stderr, "Usage: %s " - "[]\n", + "[]\n" + "\n" + "tlsproxy must be running on port 4711, " + " is the port.\n", argv[0]); return EXIT_FAILURE; } @@ -98,7 +103,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 +276,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 +295,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;