diff options
author | Julian Squires <julian@cipht.net> | 2023-03-22 14:09:57 -0230 |
---|---|---|
committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-03-28 10:12:12 -0300 |
commit | 31bfe3ef4ea898df606cb6cc59ac72de27002b01 (patch) | |
tree | 731aa1a7af0cc103912488faf36683a9e88ab4ac /posix/wordexp.c | |
parent | 07dd75589ecbedec5162a5645d57f8bd093a45db (diff) | |
download | glibc-31bfe3ef4ea898df606cb6cc59ac72de27002b01.tar.gz glibc-31bfe3ef4ea898df606cb6cc59ac72de27002b01.tar.xz glibc-31bfe3ef4ea898df606cb6cc59ac72de27002b01.zip |
posix: Fix some crashes in wordexp [BZ #18096]
Without these fixes, the first three included tests segfault (on a NULL dereference); the fourth aborts on an assertion, which is itself unnecessary. Signed-off-by: Julian Squires <julian@cipht.net> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'posix/wordexp.c')
-rw-r--r-- | posix/wordexp.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/posix/wordexp.c b/posix/wordexp.c index 0da98f5b08..b34c4a939b 100644 --- a/posix/wordexp.c +++ b/posix/wordexp.c @@ -720,7 +720,7 @@ parse_arith (char **word, size_t *word_length, size_t *max_length, ++(*offset); /* Go - evaluate. */ - if (*expr && eval_expr (expr, &numresult) != 0) + if (expr && eval_expr (expr, &numresult) != 0) { free (expr); return WRDE_SYNTAX; @@ -758,7 +758,7 @@ parse_arith (char **word, size_t *word_length, size_t *max_length, long int numresult = 0; /* Go - evaluate. */ - if (*expr && eval_expr (expr, &numresult) != 0) + if (expr && eval_expr (expr, &numresult) != 0) { free (expr); return WRDE_SYNTAX; @@ -1790,7 +1790,7 @@ envsubst: { const char *str = pattern; - if (str[0] == '\0') + if (!str || str[0] == '\0') str = _("parameter null or not set"); __fxprintf (NULL, "%s: %s\n", env, str); @@ -1883,10 +1883,7 @@ envsubst: _itoa_word (value ? strlen (value) : 0, ¶m_length[20], 10, 0)); if (free_value) - { - assert (value != NULL); - free (value); - } + free (value); return *word ? 0 : WRDE_NOSPACE; } |