]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
pop3: replace calloc + memcpy with memdup0
authorDaniel Stenberg <daniel@haxx.se>
Sun, 7 Jan 2024 15:06:32 +0000 (16:06 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 8 Jan 2024 21:55:39 +0000 (22:55 +0100)
... and make sure to return error on out of memory.

Closes #12650

lib/pop3.c

index 3e0f20a690052a470a502247773df5a384ab045b..648945ca8eb3fdd325dbf76d3e419755c1d23760 100644 (file)
@@ -77,6 +77,7 @@
 #include "curl_sasl.h"
 #include "curl_md5.h"
 #include "warnless.h"
+#include "strdup.h"
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
 #include "curl_memory.h"
@@ -670,15 +671,12 @@ static CURLcode pop3_state_servergreet_resp(struct Curl_easy *data,
           if(!timestamplen)
             break;
 
-          /* Allocate some memory for the timestamp */
-          pop3c->apoptimestamp = (char *)calloc(1, timestamplen + 1);
-
-          if(!pop3c->apoptimestamp)
+          /* dupe the timestamp */
+          pop3c->apoptimestamp = Curl_memdup0(&line[i], timestamplen);
+          if(!pop3c->apoptimestamp) {
+            result = CURLE_OUT_OF_MEMORY;
             break;
-
-          /* Copy the timestamp */
-          memcpy(pop3c->apoptimestamp, line + i, timestamplen);
-          pop3c->apoptimestamp[timestamplen] = '\0';
+          }
 
           /* If the timestamp does not contain '@' it is not (as required by
              RFC-1939) conformant to the RFC-822 message id syntax, and we
@@ -694,7 +692,8 @@ static CURLcode pop3_state_servergreet_resp(struct Curl_easy *data,
       }
     }
 
-    result = pop3_perform_capa(data, conn);
+    if(!result)
+      result = pop3_perform_capa(data, conn);
   }
 
   return result;