tool_operate: Fix error codes on bad URL & OOM

curl would erroneously report CURLE_OUT_OF_MEMORY in some cases instead
of CURLE_URL_MALFORMAT. In other cases, it would erroneously return
CURLE_URL_MALFORMAT instead of CURLE_OUT_OF_MEMORY.  Add a test case to
test the former condition.

Fixes #10130
Closes #10414
This commit is contained in:
Dan Fandrich 2023-02-04 16:05:35 -08:00 committed by Daniel Stenberg
parent a0adda4b47
commit 349c5391f2
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 117 additions and 51 deletions

View file

@ -1209,21 +1209,26 @@ static CURLcode single_transfer(struct GlobalConfig *global,
CURLU *uh = curl_url();
if(uh) {
char *updated;
if(curl_url_set(uh, CURLUPART_URL, per->this_url,
CURLU_GUESS_SCHEME)) {
result = CURLE_FAILED_INIT;
CURLUcode uerr;
uerr = curl_url_set(uh, CURLUPART_URL, per->this_url,
CURLU_GUESS_SCHEME);
if(uerr) {
result = urlerr_cvt(uerr);
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;
}
else {
Curl_safefree(per->this_url); /* free previous URL */
per->this_url = updated; /* use our new URL instead! */
uerr = curl_url_set(uh, CURLUPART_QUERY, q, CURLU_APPENDQUERY);
if(!uerr)
uerr = curl_url_get(uh, CURLUPART_URL, &updated,
CURLU_GUESS_SCHEME);
if(uerr)
result = urlerr_cvt(uerr);
else {
Curl_safefree(per->this_url); /* free previous URL */
per->this_url = updated; /* use our new URL instead! */
}
}
curl_url_cleanup(uh);
if(result)