]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
select: make Curl_socket_check take timediff_t timeout
authorDaniel Stenberg <daniel@haxx.se>
Wed, 15 Apr 2020 08:27:20 +0000 (10:27 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 23 Apr 2020 13:57:23 +0000 (15:57 +0200)
Coverity found CID 1461718:

Integer handling issues (CONSTANT_EXPRESSION_RESULT) "timeout_ms >
9223372036854775807L" is always false regardless of the values of its
operands. This occurs as the logical second operand of "||".

Closes #5240

lib/gopher.c
lib/select.c
lib/select.h
lib/socks.c
lib/vtls/schannel.c

index 4216e6136b104f7ec41876aa8451993894ecab6f..c48098f7540f5ffb2e75846bf52c4312b8647973 100644 (file)
@@ -147,8 +147,8 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
       result = CURLE_OPERATION_TIMEDOUT;
       break;
     }
-    if(!timeout_ms || timeout_ms > TIME_T_MAX)
-      timeout_ms = TIME_T_MAX;
+    if(!timeout_ms)
+      timeout_ms = TIMEDIFF_T_MAX;
 
     /* Don't busyloop. The entire loop thing is a work-around as it causes a
        BLOCKING behavior which is a NO-NO. This function should rather be
@@ -156,7 +156,7 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
        possible to send now will be sent in the doing function repeatedly
        until the entire request is sent.
     */
-    what = SOCKET_WRITABLE(sockfd, (time_t)timeout_ms);
+    what = SOCKET_WRITABLE(sockfd, timeout_ms);
     if(what < 0) {
       result = CURLE_SEND_ERROR;
       break;
index 857e7f698d0cd0c9d50993fdaebdc31b184b8e4d..d91b20a4bcec810294bed939843927fd3841a744 100644 (file)
@@ -201,7 +201,7 @@ int Curl_select(curl_socket_t maxfd,
 int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
                       curl_socket_t readfd1,
                       curl_socket_t writefd, /* socket to write to */
-                      time_t timeout_ms)     /* milliseconds to wait */
+                      timediff_t timeout_ms)     /* milliseconds to wait */
 {
 #ifdef HAVE_POLL_FINE
   struct pollfd pfd[3];
@@ -333,7 +333,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
      curl_socket_t is unsigned in such cases and thus -1 is the largest
      value).
   */
-  r = Curl_select(maxfd, &fds_read, &fds_write, &fds_err, timeout_ms);
+  r = Curl_select(maxfd, &fds_read, &fds_write, &fds_err, (time_t)timeout_ms);
 
   if(r < 0)
     return -1;
index 2667d0ccf37d96272cc7e6a9f32e10fd5d17105f..0fd8ed51523d9e81bfa72a1ba3333734f18d53a2 100644 (file)
@@ -80,7 +80,7 @@ int Curl_select(curl_socket_t maxfd,
 
 int Curl_socket_check(curl_socket_t readfd, curl_socket_t readfd2,
                       curl_socket_t writefd,
-                      time_t timeout_ms);
+                      timediff_t timeout_ms);
 #define SOCKET_READABLE(x,z) \
   Curl_socket_check(x, CURL_SOCKET_BAD, CURL_SOCKET_BAD, z)
 #define SOCKET_WRITABLE(x,z) \
index dfd944ef341675eb985e6a9e933b8372e9653e73..18affbc964061aadf668b0c64c81d039cb346fc4 100644 (file)
@@ -68,9 +68,9 @@ int Curl_blockread_all(struct connectdata *conn, /* connection data */
       result = CURLE_OPERATION_TIMEDOUT;
       break;
     }
-    if(!timeout_ms || timeout_ms > TIME_T_MAX)
+    if(!timeout_ms)
       timeout_ms = TIME_T_MAX;
-    if(SOCKET_READABLE(sockfd, (time_t)timeout_ms) <= 0) {
+    if(SOCKET_READABLE(sockfd, timeout_ms) <= 0) {
       result = ~CURLE_OK;
       break;
     }
index dce6242da6a1fb05b085b8f572dfe50aec9f5cfe..49659bb7ab2741f1b152e014b84e8303bfca0147 100644 (file)
@@ -1645,9 +1645,9 @@ schannel_send(struct connectdata *conn, int sockindex,
         written = -1;
         break;
       }
-      if(!timeout_ms || timeout_ms > TIME_T_MAX)
-        timeout_ms = TIME_T_MAX;
-      what = SOCKET_WRITABLE(conn->sock[sockindex], (time_t)timeout_ms);
+      if(!timeout_ms)
+        timeout_ms = TIMEDIFF_T_MAX;
+      what = SOCKET_WRITABLE(conn->sock[sockindex], timeout_ms);
       if(what < 0) {
         /* fatal error */
         failf(conn->data, "select/poll on SSL socket, errno: %d", SOCKERRNO);