diff options
author | Daniel Stenberg <daniel@haxx.se> | 2022-10-12 08:42:57 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2022-10-14 08:15:55 +0200 |
commit | f67f60c14bf8a0cff4ac611d12448304ce998114 (patch) | |
tree | 2c49067a89627f1baa8bb2a2b9220458d01f1f75 /src | |
parent | 57e2bb52aaa7d16adef6d3d1c4b75c242148a85e (diff) | |
download | curl-f67f60c14bf8a0cff4ac611d12448304ce998114.tar.gz |
curl/add_parallel_transfers: better error handling
1 - consider the transfer handled at once when in the function, to avoid
the same list entry to get added more than once in rare error
situations
2 - set the ERRORBUFFER for the handle first after it has been added
successfully
Reported-by: Trail of Bits
Closes #9729
Diffstat (limited to 'src')
-rw-r--r-- | src/tool_operate.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c index 544c04a29..c64b17d06 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -2192,17 +2192,15 @@ static CURLcode add_parallel_transfers(struct GlobalConfig *global, sleeping = TRUE; continue; } + per->added = TRUE; result = pre_transfer(global, per); if(result) return result; - errorbuf = per->errorbuffer; - if(!errorbuf) { - errorbuf = malloc(CURL_ERROR_SIZE); - if(!errorbuf) - return CURLE_OUT_OF_MEMORY; - } + errorbuf = malloc(CURL_ERROR_SIZE); + if(!errorbuf) + return CURLE_OUT_OF_MEMORY; /* parallel connect means that we don't set PIPEWAIT since pipewait will make libcurl prefer multiplexing */ @@ -2212,19 +2210,21 @@ static CURLcode add_parallel_transfers(struct GlobalConfig *global, (void)curl_easy_setopt(per->curl, CURLOPT_XFERINFOFUNCTION, xferinfo_cb); (void)curl_easy_setopt(per->curl, CURLOPT_XFERINFODATA, per); (void)curl_easy_setopt(per->curl, CURLOPT_NOPROGRESS, 0L); - (void)curl_easy_setopt(per->curl, CURLOPT_ERRORBUFFER, errorbuf); mcode = curl_multi_add_handle(multi, per->curl); if(mcode) { - free(errorbuf); - return CURLE_OUT_OF_MEMORY; + DEBUGASSERT(mcode == CURLM_OUT_OF_MEMORY); + result = CURLE_OUT_OF_MEMORY; } - result = create_transfer(global, share, &getadded); + if(!result) + result = create_transfer(global, share, &getadded); if(result) { free(errorbuf); return result; } + errorbuf[0] = 0; + (void)curl_easy_setopt(per->curl, CURLOPT_ERRORBUFFER, errorbuf); per->errorbuffer = errorbuf; per->added = TRUE; all_added++; |