pop3: replace calloc + memcpy with memdup0

... and make sure to return error on out of memory.

Closes #12650
This commit is contained in:
Daniel Stenberg 2024-01-07 16:06:32 +01:00
parent cfe7902111
commit a3abc81a48
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

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