]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Curl_send: return error when pre_receive_plain can't malloc
authorDaniel Stenberg <daniel@haxx.se>
Thu, 24 Sep 2020 22:12:10 +0000 (00:12 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 25 Sep 2020 06:31:52 +0000 (08:31 +0200)
... will probably trigger some false DEAD CODE positives on non-windows
code analyzers for the conditional code.

Closes #6011

lib/sendf.c

index 6943fa84e006283c30e2fbc18eecf272bacee13d..157787a37be9313a243df3cab7b7b6a6363f1610 100644 (file)
@@ -140,7 +140,7 @@ bool Curl_recv_has_postponed_data(struct connectdata *conn, int sockindex)
          psnd->recv_size > psnd->recv_processed;
 }
 
-static void pre_receive_plain(struct connectdata *conn, int num)
+static CURLcode pre_receive_plain(struct connectdata *conn, int num)
 {
   const curl_socket_t sockfd = conn->sock[num];
   struct postponed_data * const psnd = &(conn->postponed[num]);
@@ -161,6 +161,8 @@ static void pre_receive_plain(struct connectdata *conn, int num)
         /* Use buffer double default size for intermediate buffer */
         psnd->allocated_size = 2 * conn->data->set.buffer_size;
         psnd->buffer = malloc(psnd->allocated_size);
+        if(!psnd->buffer)
+          return CURLE_OUT_OF_MEMORY;
         psnd->recv_size = 0;
         psnd->recv_processed = 0;
 #ifdef DEBUGBUILD
@@ -180,6 +182,7 @@ static void pre_receive_plain(struct connectdata *conn, int num)
         psnd->allocated_size = 0;
     }
   }
+  return CURLE_OK;
 }
 
 static ssize_t get_pre_recved(struct connectdata *conn, int num, char *buf,
@@ -225,7 +228,7 @@ bool Curl_recv_has_postponed_data(struct connectdata *conn, int sockindex)
   (void)sockindex;
   return false;
 }
-#define pre_receive_plain(c,n) do {} while(0)
+#define pre_receive_plain(c,n) CURLE_OK
 #define get_pre_recved(c,n,b,l) 0
 #endif /* ! USE_RECV_BEFORE_SEND_WORKAROUND */
 
@@ -379,7 +382,10 @@ ssize_t Curl_send_plain(struct connectdata *conn, int num,
      To avoid lossage of received data, recv() must be
      performed before every send() if any incoming data is
      available. */
-  pre_receive_plain(conn, num);
+  if(pre_receive_plain(conn, num)) {
+    *code = CURLE_OUT_OF_MEMORY;
+    return -1;
+  }
 
 #if defined(MSG_FASTOPEN) && !defined(TCP_FASTOPEN_CONNECT) /* Linux */
   if(conn->bits.tcp_fastopen) {