]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
duphandle: use strdup to clone *COPYPOSTFIELDS if size is not set
authorDaniel Stenberg <daniel@haxx.se>
Mon, 13 Nov 2023 14:50:24 +0000 (15:50 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 13 Nov 2023 16:50:00 +0000 (17:50 +0100)
Previously it would unconditionally use the size, which is set to -1
when strlen is requested.

Updated test 544 to verify.

Closes #12317

lib/easy.c
tests/libtest/lib544.c

index 2ec4f5d73f919ca7e53ee238d8b442098cd25e63..3341f466149547be74229bff84d405544b21b9af 100644 (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 */
index 192bfb2e707dbe6501751e1748e04770eab64a5f..a58fa05e3e5fea4a794a5a5d883f017ab96e7a04 100644 (file)
@@ -63,7 +63,6 @@ int test(char *URL)
   /* Update the original data to detect non-copy. */
   strcpy(teststring, "FAIL");
 
-#ifdef LIB545
   {
     CURL *handle2;
     handle2 = curl_easy_duphandle(curl);
@@ -71,7 +70,6 @@ int test(char *URL)
 
     curl = handle2;
   }
-#endif
 
   /* Now, this is a POST request with binary 0 embedded in POST data. */
   res = curl_easy_perform(curl);