diff options
author | Anton Moryakov <ant.v.moryakov@gmail.com> | 2025-02-07 01:01:23 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-02-11 08:17:23 -0600 |
commit | b4df7003dfd06da630c248c958993a686fb1619b (patch) | |
tree | e138100fc9bd9b63bcaae69140443d2d8b0e84c2 /common | |
parent | bdf056441de30e639d2bc80c32027de3bf28ac4a (diff) |
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 <ant.v.moryakov@gmail.com>
Diffstat (limited to 'common')
-rw-r--r-- | common/cli_hush.c | 8 |
1 files changed, 7 insertions, 1 deletions
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 { |