From: Anton Moryakov Date: Thu, 6 Feb 2025 22:01:23 +0000 (+0300) Subject: common: Add NULL checks for xrealloc in make_string cli_hush.c X-Git-Tag: v2025.07-rc1~18^2~106 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4df7003dfd06da630c248c958993a686fb1619b;p=pandora-u-boot.git common: Add NULL checks for xrealloc in make_string cli_hush.c - Check return value of xrealloc for NULL. - Free allocated memory and return NULL if xrealloc fails. - Prevent NULL pointer dereference in strlen and strcat. Triggers found by static analyzer Svace. Signed-off-by: Anton Moryakov --- diff --git a/common/cli_hush.c b/common/cli_hush.c index a6a8edce1f4..9f437ae5f47 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -3626,7 +3626,13 @@ static char *make_string(char **inp, int *nonnull) noeval = 1; for (n = 0; inp[n]; n++) { p = insert_var_value_sub(inp[n], noeval); - str = xrealloc(str, (len + strlen(p) + (2 * nonnull[n]))); + char *new_str = xrealloc(str, (len + strlen(p) + (2 * nonnull[n]))); + if (!new_str) { + free(str); + if (p != inp[n]) free(p); + return NULL; + } + str = new_str; if (n) { strcat(str, " "); } else {