]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
vtls: receive max buffer
authorStefan Eissing <stefan@eissing.org>
Fri, 26 Jan 2024 09:10:11 +0000 (10:10 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 26 Jan 2024 14:46:15 +0000 (15:46 +0100)
- do not only receive one TLS record, but try to fill
  the passed buffer
- consider <4K remaning space is "filled".

Closes #12801

lib/vtls/vtls.c

index 7f6ce09d7cf9614f4259112e4fd46aea8c8600e7..e928ba5d079e6e3fb44cdff47c5503847ace8f7b 100644 (file)
@@ -1715,18 +1715,34 @@ static ssize_t ssl_cf_recv(struct Curl_cfilter *cf,
 {
   struct cf_call_data save;
   ssize_t nread;
+  size_t ntotal = 0;
 
   CF_DATA_SAVE(save, cf, data);
   *err = CURLE_OK;
-  nread = Curl_ssl->recv_plain(cf, data, buf, len, err);
-  if(nread > 0) {
-    DEBUGASSERT((size_t)nread <= len);
-  }
-  else if(nread == 0) {
-    /* eof */
+  /* Do receive until we fill the buffer somehwhat or EGAIN, error or EOF */
+  while(!ntotal || (len - ntotal) > (4*1024)) {
     *err = CURLE_OK;
+    nread = Curl_ssl->recv_plain(cf, data, buf + ntotal, len - ntotal, err);
+    if(nread < 0) {
+      if(*err == CURLE_AGAIN && ntotal > 0) {
+        /* we EAGAINed after having reed data, return the success amount */
+        *err = CURLE_OK;
+        break;
+      }
+      /* we have a an error to report */
+      goto out;
+    }
+    else if(nread == 0) {
+      /* eof */
+      break;
+    }
+    ntotal += (size_t)nread;
+    DEBUGASSERT((size_t)ntotal <= len);
   }
-  CURL_TRC_CF(data, cf, "cf_recv(len=%zu) -> %zd, %d", len, nread, *err);
+  nread = (ssize_t)ntotal;
+out:
+  CURL_TRC_CF(data, cf, "cf_recv(len=%zu) -> %zd, %d", len,
+              nread, *err);
   CF_DATA_RESTORE(cf, save);
   return nread;
 }