aboutsummaryrefslogtreecommitdiffstats
path: root/debuginfod
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2020-06-17 00:08:23 +0200
committerMark Wielaard <mark@klomp.org>2020-06-24 16:37:35 +0200
commitd45cc8a04a2dab73e847808761c1b0eb861a7c24 (patch)
tree47cf788dcefb39e6e2792b73d8f4fd4d3de874a8 /debuginfod
parent90808ed559792a70b79c39183b88df09234866cf (diff)
downloadplatform_external_elfutils-d45cc8a04a2dab73e847808761c1b0eb861a7c24.tar.gz
platform_external_elfutils-d45cc8a04a2dab73e847808761c1b0eb861a7c24.tar.bz2
platform_external_elfutils-d45cc8a04a2dab73e847808761c1b0eb861a7c24.zip
debuginfod: Make sure handle_data can be allocated and is always freed.
When allocating handle_data we should check for out of memory failures. Also when the allocation has succeeded make sure we always clean up by going to out1 on any future errors. So move the curl_multi_init call earlier, because that goes to out0 on failure. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'debuginfod')
-rw-r--r--debuginfod/ChangeLog5
-rw-r--r--debuginfod/debuginfod-client.c22
2 files changed, 19 insertions, 8 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index d6bbfac8..2bbd5db5 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,5 +1,10 @@
2020-06-16 Mark Wielaard <mark@klomp.org>
+ * debuginfod-client.c (debuginfod_query_server): Check malloc.
+ Move curl_multi_init call before handle_data malloc call.
+
+2020-06-16 Mark Wielaard <mark@klomp.org>
+
* debuginfod-client.c (debuginfod_query_server): Replace sizeof
build_id_bytes check with strlen build_id check.
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 7b53cb31..c2aa4e10 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -665,10 +665,24 @@ debuginfod_query_server (debuginfod_client *c,
&& (i == 0 || server_urls[i - 1] == url_delim_char))
num_urls++;
+ CURLM *curlm = curl_multi_init();
+ if (curlm == NULL)
+ {
+ rc = -ENETUNREACH;
+ goto out0;
+ }
+
/* Tracks which handle should write to fd. Set to the first
handle that is ready to write the target file to the cache. */
CURL *target_handle = NULL;
struct handle_data *data = malloc(sizeof(struct handle_data) * num_urls);
+ if (data == NULL)
+ {
+ rc = -ENOMEM;
+ goto out0;
+ }
+
+ /* thereafter, goto out1 on error. */
/* Initalize handle_data with default values. */
for (int i = 0; i < num_urls; i++)
@@ -677,14 +691,6 @@ debuginfod_query_server (debuginfod_client *c,
data[i].fd = -1;
}
- CURLM *curlm = curl_multi_init();
- if (curlm == NULL)
- {
- rc = -ENETUNREACH;
- goto out0;
- }
- /* thereafter, goto out1 on error. */
-
char *strtok_saveptr;
char *server_url = strtok_r(server_urls, url_delim, &strtok_saveptr);