mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 12:30:06 +00:00
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>
This commit is contained in:
parent
07dd75589e
commit
31bfe3ef4e
@ -117,6 +117,8 @@ struct test_case_struct
|
||||
{ 0, NULL, "$((010+0x10))", 0, 1, { "24" }, IFS },
|
||||
{ 0, NULL, "$((-010+0x10))", 0, 1, { "8" }, IFS },
|
||||
{ 0, NULL, "$((-0x10+010))", 0, 1, { "-8" }, IFS },
|
||||
{ 0, NULL, "$(())", 0, 1, { "0", }, IFS },
|
||||
{ 0, NULL, "$[]", 0, 1, { "0", }, IFS },
|
||||
|
||||
/* Advanced parameter expansion */
|
||||
{ 0, NULL, "${var:-bar}", 0, 1, { "bar", }, IFS },
|
||||
@ -138,6 +140,8 @@ struct test_case_struct
|
||||
{ 0, "12345", "${#var}", 0, 1, { "5", }, IFS },
|
||||
{ 0, NULL, "${var:-'}'}", 0, 1, { "}", }, IFS },
|
||||
{ 0, NULL, "${var-}", 0, 0, { NULL }, IFS },
|
||||
{ 0, NULL, "${a?}", 0, 0, { NULL, }, IFS },
|
||||
{ 0, NULL, "${#a=}", 0, 1, { "0", }, IFS },
|
||||
|
||||
{ 0, "pizza", "${var#${var}}", 0, 0, { NULL }, IFS },
|
||||
{ 0, "pepperoni", "${var%$(echo oni)}", 0, 1, { "pepper" }, IFS },
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user