]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_operate: provide better errmsg for -G with bad URL
authorDaniel Stenberg <daniel@haxx.se>
Fri, 11 Nov 2022 14:46:17 +0000 (15:46 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 11 Nov 2022 23:45:24 +0000 (00:45 +0100)
If the URL that -G would try to add a query to could not be parsed, it would
display

 curl: (27) Out of memory

It now instead shows:

 curl: (2) Could not parse the URL, failed to set query

Reported-by: Alex Xu
Fixes #9889
Closes #9892

src/tool_operate.c

index 8ec2da6796d0dd28e1eaadf895bf8eb5a5172526..52b766db9cb71564c0ebd9c72b33155eb46f8cb2 100644 (file)
@@ -1195,16 +1195,24 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           if(uh) {
             char *updated;
             if(curl_url_set(uh, CURLUPART_URL, per->this_url,
-                            CURLU_GUESS_SCHEME) ||
-               curl_url_set(uh, CURLUPART_QUERY, q, CURLU_APPENDQUERY) ||
-               curl_url_get(uh, CURLUPART_URL, &updated, CURLU_GUESS_SCHEME)) {
-              curl_url_cleanup(uh);
+                            CURLU_GUESS_SCHEME)) {
+              result = CURLE_FAILED_INIT;
+              errorf(global, "(%d) Could not parse the URL, "
+                     "failed to set query\n", result);
+              config->synthetic_error = TRUE;
+            }
+            else if(curl_url_set(uh, CURLUPART_QUERY, q, CURLU_APPENDQUERY) ||
+                    curl_url_get(uh, CURLUPART_URL, &updated,
+                                 CURLU_GUESS_SCHEME)) {
               result = CURLE_OUT_OF_MEMORY;
-              break;
             }
-            Curl_safefree(per->this_url); /* free previous URL */
-            per->this_url = updated; /* use our new URL instead! */
+            else {
+              Curl_safefree(per->this_url); /* free previous URL */
+              per->this_url = updated; /* use our new URL instead! */
+            }
             curl_url_cleanup(uh);
+            if(result)
+              break;
           }
         }