From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from so254-44.mailgun.net (so254-44.mailgun.net [198.61.254.44]) by sourceware.org (Postfix) with UTF8SMTPS id 663D63858D3C for ; Wed, 22 Mar 2023 16:40:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 663D63858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cipht.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mg.cipht.net DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.cipht.net; q=dns/txt; s=mailo; t=1679503215; x=1679510415; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Subject: Cc: To: To: From: From: Sender: Sender; bh=oVXfZShLr2Bm1Bf6Rl0luOwrODWmqAZVE9Ykw0fay6g=; b=EOGoIHMMBm7tvCcrQW09ksh/OhjsygevLSRQjSISEmxv7QvEht+uS3M1cbZVY24ZH2l+HqIMdIU/pnfABokvOFlGGLc4pAZhkQmTVeVYAf9qDn6IMW6G0RLtEm8EJGnMuS47XeIpuKm5wTew2GumA5R3Gw+g1DtLe3L2szyxPIY= X-Mailgun-Sending-Ip: 198.61.254.44 X-Mailgun-Sid: WyIwMzc2OCIsImxpYmMtYWxwaGFAc291cmNld2FyZS5vcmciLCJkMWMxM2MiXQ== Received: from localhost.localdomain (mtprnf0117w-47-55-251-45.dhcp-dynamic.fibreop.nl.bellaliant.net [47.55.251.45]) by a279fb0fb91b with SMTP id 641b2f6fd7a1f1026af019d0 (version=TLS1.3, cipher=TLS_AES_128_GCM_SHA256); Wed, 22 Mar 2023 16:40:15 GMT Sender: julian=cipht.net@mg.cipht.net From: Julian Squires To: libc-alpha@sourceware.org Cc: Julian Squires Subject: [PATCH v2] posix: Fix some crashes in wordexp [BZ #18096] Date: Wed, 22 Mar 2023 14:09:57 -0230 Message-Id: <20230322163957.9710-1-julian@cipht.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318125950.3611824-1-julian@cipht.net> References: <20230318125950.3611824-1-julian@cipht.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --- v2: removed the assert under seen_hash as requested. Thanks for the review. posix/wordexp-test.c | 4 ++++ posix/wordexp.c | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c index f7a591149b..bae27d6cee 100644 --- a/posix/wordexp-test.c +++ b/posix/wordexp-test.c @@ -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 }, 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; } -- 2.39.2