From: LiFeng Date: Sat, 12 Jun 2021 06:52:46 +0000 (+0800) Subject: string utils: Make sure don't return uninitialized memory. X-Git-Tag: lxc-5.0.0~157^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47f5be06a4793f46cc5e609261486ce072ffcb80;p=thirdparty%2Flxc.git string utils: Make sure don't return uninitialized memory. The function lxc_string_split_quoted and lxc_string_split_and_trim use realloc to reduce the memory. But the result may be NULL, the the returned memory will be uninitialized Signed-off-by: LiFeng --- diff --git a/src/lxc/string_utils.c b/src/lxc/string_utils.c index 9c54819a0..b1d6dc9bc 100644 --- a/src/lxc/string_utils.c +++ b/src/lxc/string_utils.c @@ -404,6 +404,9 @@ char **lxc_string_split_quoted(char *string) if (state == 'a') complete_word(&result, nextword, p, &result_capacity, &result_count); + if (result == NULL) + return calloc(1, sizeof(char *)); + return realloc(result, (result_count + 1) * sizeof(char *)); } @@ -443,6 +446,9 @@ char **lxc_string_split_and_trim(const char *string, char _sep) result_count++; } + if (result == NULL) + return calloc(1, sizeof(char *)); + /* if we allocated too much, reduce it */ return realloc(result, (result_count + 1) * sizeof(char *));