From a96a2d7718152afeb22f5e6aa4b6fd1bb7735992 Mon Sep 17 00:00:00 2001 From: Tobias Schramm Date: Tue, 20 Feb 2018 12:12:50 +0100 Subject: [PATCH] autoupdater: Replace mallocs with safe_malloc During parsing of cinfiguration multiple null ptr dereferences were possible due to a lack of NULL checks Signed-off-by: Tobias Schramm --- admin/autoupdater/src/settings.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/admin/autoupdater/src/settings.c b/admin/autoupdater/src/settings.c index cc9d17a..50a7afb 100644 --- a/admin/autoupdater/src/settings.c +++ b/admin/autoupdater/src/settings.c @@ -27,6 +27,7 @@ #include "settings.h" #include "hexutil.h" +#include "util.h" #include @@ -97,7 +98,7 @@ static const char ** load_string_list(struct uci_context *ctx, struct uci_sectio i++; *len = i; - const char **ret = malloc(i * sizeof(char *)); + const char **ret = safe_malloc(i * sizeof(char *), "failed to allocate string list"); i = 0; uci_foreach_element(&o->v.list, e) @@ -154,7 +155,7 @@ void load_settings(struct settings *settings) { settings->mirrors = load_string_list(ctx, branch, "mirror", &settings->n_mirrors); const char **pubkeys_str = load_string_list(ctx, branch, "pubkey", &settings->n_pubkeys); - settings->pubkeys = malloc(settings->n_pubkeys * sizeof(ecc_25519_work_t)); + settings->pubkeys = safe_malloc(settings->n_pubkeys * sizeof(ecc_25519_work_t), "failed to allocate memory for public keys"); size_t ignored_keys = 0; for (size_t i = 0; i < settings->n_pubkeys; i++) { ecc_int256_t pubkey_packed;