]> ruderich.org/simon Gitweb - tlsproxy/tlsproxy.git/blobdiff - src/connection.c
Add two assert()s.
[tlsproxy/tlsproxy.git] / src / connection.c
index ed1bc63c6e030c5349f9d2aa46a179c8d60bf2f9..2875b768b90ccf71714d03124f41c0de9fbe721c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <limits.h>
 #include <netdb.h>
 #include <poll.h>
 #include <unistd.h>
@@ -156,7 +157,7 @@ void handle_connection(int client_socket) {
         server_socket = connect_to_host(host, port);
     }
 
-    if (server_socket == -1) {
+    if (server_socket < 0) {
         LOG(WARNING, "failed to connect to server");
         send_forwarding_failure(client_fd_write);
         goto out;
@@ -528,6 +529,7 @@ static int read_http_request(FILE *client_fd, char *request, size_t length) {
     char buffer[MAX_REQUEST_LINE];
     int found_proxy_authorization;
 
+    assert(length <= INT_MAX);
     if (fgets(request, (int)length, client_fd) == NULL) {
         if (ferror(client_fd)) {
             LOG_PERROR(WARNING, "read_http_request(): fgets()");
@@ -816,12 +818,12 @@ static int connect_to_host(const char *hostname, const char *port) {
         server_socket = socket(server->ai_family,
                                server->ai_socktype,
                                server->ai_protocol);
-        if (server_socket == -1) {
+        if (server_socket < 0) {
             LOG_PERROR(DEBUG, "connect_to_host(): socket(), trying next");
             continue;
         }
 
-        if (connect(server_socket, server->ai_addr, server->ai_addrlen) != -1) {
+        if (connect(server_socket, server->ai_addr, server->ai_addrlen) == 0) {
             break;
         }
         LOG_PERROR(DEBUG, "connect_to_host(): connect(), trying next");