]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
schannel: Fix blocking timeout logic
authorAndrew Kurushin <ajax16384@gmail.com>
Sun, 12 Apr 2020 10:07:51 +0000 (13:07 +0300)
committerJay Satiro <raysatiro@yahoo.com>
Sun, 12 Apr 2020 22:32:17 +0000 (18:32 -0400)
- Fix schannel_send for the case when no timeout was set.

Prior to this change schannel would error if the socket was not ready
to send data and no timeout was set.

This commit is similar to parent commit 89dc6e0 which recently made the
same change for SOCKS, for the same reason. Basically it was not well
understood that when Curl_timeleft returns 0 it is not a timeout of 0 ms
but actually means no timeout.

Fixes https://github.com/curl/curl/issues/5177
Closes https://github.com/curl/curl/pull/5221

lib/vtls/schannel.c

index cb70d530981726f0b48e48a23cc85b450c6b2c9c..96c1dbc674273d337fcf3dcafe709d175226d9d3 100644 (file)
@@ -1631,13 +1631,13 @@ schannel_send(struct connectdata *conn, int sockindex,
     /* send entire message or fail */
     while(len > (size_t)written) {
       ssize_t this_write;
-      timediff_t timeleft;
+      timediff_t timeout_ms;
       int what;
 
       this_write = 0;
 
-      timeleft = Curl_timeleft(conn->data, NULL, FALSE);
-      if(timeleft < 0) {
+      timeout_ms = Curl_timeleft(conn->data, NULL, FALSE);
+      if(timeout_ms < 0) {
         /* we already got the timeout */
         failf(conn->data, "schannel: timed out sending data "
               "(bytes sent: %zd)", written);
@@ -1645,9 +1645,9 @@ schannel_send(struct connectdata *conn, int sockindex,
         written = -1;
         break;
       }
-      if(timeleft > TIME_T_MAX)
-        timeleft = TIME_T_MAX;
-      what = SOCKET_WRITABLE(conn->sock[sockindex], (time_t)timeleft);
+      if(!timeout_ms || timeout_ms > TIME_T_MAX)
+        timeout_ms = TIME_T_MAX;
+      what = SOCKET_WRITABLE(conn->sock[sockindex], (time_t)timeout_ms);
       if(what < 0) {
         /* fatal error */
         failf(conn->data, "select/poll on SSL socket, errno: %d", SOCKERRNO);