Avoid NULL deference in curl_check_finished_download

We have not set handle in the function at this stage, so we can not
assign an error to it.  Pass the handle to the function to avoid
waiting until the payload is retrieved.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2022-12-13 00:18:03 +10:00
parent 775d511f42
commit 471a030466

View file

@ -473,10 +473,9 @@ static int curl_retry_next_server(CURLM *curlm, CURL *curl, struct dload_payload
* Returns -1 if an error happened for a required file * Returns -1 if an error happened for a required file
* Returns -2 if an error happened for an optional file * Returns -2 if an error happened for an optional file
*/ */
static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg, static int curl_check_finished_download(alpm_handle_t *handle, CURLM *curlm, CURLMsg *msg,
const char *localpath, int *active_downloads_num) const char *localpath, int *active_downloads_num)
{ {
alpm_handle_t *handle = NULL;
struct dload_payload *payload = NULL; struct dload_payload *payload = NULL;
CURL *curl = msg->easy_handle; CURL *curl = msg->easy_handle;
CURLcode curlerr; CURLcode curlerr;
@ -491,7 +490,6 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg,
curlerr = curl_easy_getinfo(curl, CURLINFO_PRIVATE, &payload); curlerr = curl_easy_getinfo(curl, CURLINFO_PRIVATE, &payload);
ASSERT(curlerr == CURLE_OK, RET_ERR(handle, ALPM_ERR_LIBCURL, -1)); ASSERT(curlerr == CURLE_OK, RET_ERR(handle, ALPM_ERR_LIBCURL, -1));
handle = payload->handle;
curl_gethost(payload->fileurl, hostname, sizeof(hostname)); curl_gethost(payload->fileurl, hostname, sizeof(hostname));
curlerr = msg->data.result; curlerr = msg->data.result;
@ -919,7 +917,7 @@ static int curl_download_internal(alpm_handle_t *handle,
break; break;
} }
if(msg->msg == CURLMSG_DONE) { if(msg->msg == CURLMSG_DONE) {
int ret = curl_check_finished_download(curlm, msg, int ret = curl_check_finished_download(handle, curlm, msg,
localpath, &active_downloads_num); localpath, &active_downloads_num);
if(ret == -1) { if(ret == -1) {
/* if current payload failed to download then stop adding new payloads but wait for the /* if current payload failed to download then stop adding new payloads but wait for the