duphandle: use strdup to clone *COPYPOSTFIELDS if size is not set

Previously it would unconditionally use the size, which is set to -1
when strlen is requested.

Updated test 544 to verify.

Closes #12317
This commit is contained in:
Daniel Stenberg 2023-11-13 15:50:24 +01:00
parent addabb1794
commit baf7b803b3
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 7 additions and 6 deletions

View file

@ -858,10 +858,13 @@ static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
/* duplicate memory areas pointed to */
i = STRING_COPYPOSTFIELDS;
if(src->set.postfieldsize && src->set.str[i]) {
/* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
dst->set.str[i] = Curl_memdup(src->set.str[i],
curlx_sotouz(src->set.postfieldsize));
if(src->set.str[i]) {
if(src->set.postfieldsize == -1)
dst->set.str[i] = strdup(src->set.str[i]);
else
/* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
dst->set.str[i] = Curl_memdup(src->set.str[i],
curlx_sotouz(src->set.postfieldsize));
if(!dst->set.str[i])
return CURLE_OUT_OF_MEMORY;
/* point to the new copy */