]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
TLS: prevent shutdown loops to get stuck
authorDaniel Stenberg <daniel@haxx.se>
Thu, 17 Jun 2021 08:24:41 +0000 (10:24 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 17 Jun 2021 15:06:21 +0000 (17:06 +0200)
... by making sure the loops are only allowed to read the shutdown
traffic a limited number of times.

Reported-by: Harry Sintonen
Closes #7271

lib/vtls/gskit.c
lib/vtls/openssl.c
lib/vtls/sectransp.c

index ca953769d1baf9ca23c48f4e642afd496a50bd89..281bb52bb476b4fae29da2055e1b241594fa9020 100644 (file)
@@ -1192,6 +1192,7 @@ static int gskit_shutdown(struct Curl_easy *data,
   int what;
   int rc;
   char buf[120];
+  int loop = 10; /* don't get stuck */
 
   if(!BACKEND->handle)
     return 0;
@@ -1206,7 +1207,7 @@ static int gskit_shutdown(struct Curl_easy *data,
   what = SOCKET_READABLE(conn->sock[sockindex],
                          SSL_SHUTDOWN_TIMEOUT);
 
-  for(;;) {
+  while(loop--) {
     ssize_t nread;
 
     if(what < 0) {
index 9ce6f68354ad219412ea17e3098ff1751f22dd4e..e4aa26ac1f5fd5a0cf9df1f84463cc2865f9b9f6 100644 (file)
@@ -1448,6 +1448,7 @@ static int ossl_shutdown(struct Curl_easy *data,
   int err;
   bool done = FALSE;
   struct ssl_backend_data *backend = connssl->backend;
+  int loop = 10;
 
 #ifndef CURL_DISABLE_FTP
   /* This has only been tested on the proftpd server, and the mod_tls code
@@ -1461,7 +1462,7 @@ static int ossl_shutdown(struct Curl_easy *data,
 
   if(backend->handle) {
     buffsize = (int)sizeof(buf);
-    while(!done) {
+    while(!done && loop--) {
       int what = SOCKET_READABLE(conn->sock[sockindex],
                                  SSL_SHUTDOWN_TIMEOUT);
       if(what > 0) {
index edd375ea7d7349fc80c931213f5a06654fe2294c..451b6cdb6b907550593073c75eb94023fb2c86de 100644 (file)
@@ -3148,6 +3148,7 @@ static int sectransp_shutdown(struct Curl_easy *data,
   int what;
   int rc;
   char buf[120];
+  int loop = 10; /* avoid getting stuck */
 
   if(!backend->ssl_ctx)
     return 0;
@@ -3163,7 +3164,7 @@ static int sectransp_shutdown(struct Curl_easy *data,
 
   what = SOCKET_READABLE(conn->sock[sockindex], SSL_SHUTDOWN_TIMEOUT);
 
-  for(;;) {
+  while(loop--) {
     if(what < 0) {
       /* anything that gets here is fatally bad */
       failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);