#include <config.h>
#include <arpa/inet.h>
+#include <assert.h>
#include <errno.h>
+#include <limits.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
}
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;
}
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()");
if (ferror(client_fd)) {
perror("read_http_request(): fgets()");
return -1;
+ } else if (feof(client_fd)) {
+ return -2;
}
return 0;