From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by sourceware.org (Postfix) with ESMTPS id 2EB563858D39 for ; Tue, 28 Mar 2023 13:09:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EB563858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc32.google.com with SMTP id m6-20020a4ae846000000b0053b9059edd5so1855784oom.3 for ; Tue, 28 Mar 2023 06:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680008985; h=content-transfer-encoding:in-reply-to:organization:content-language :references:to:subject:from:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=yj+KcaJkAacnxZEaTvGU229rPcHkz6VmMv9fP22xoYc=; b=nikRU5b3NEwidxDe4YXrCDKhjWCuLr96NU82ECrMI3eV/2bkEeCkrOeh8Fdpuu7YlY i+HyYLU2zRJbuXA82+Ewyf90JxkYCT8peRgC7QaCLZb1BQ3k+JzI8MFrSxKT5SBbkd0X nNVLEBefe8PID/s/SsmynskctKxaFCis3ZXKPXFPttLDs0fZEKER9wab2Gvo0mc6jjV7 NYF04Oy3u97gwXgTjgxQuKmcCHBkmzClgFeLUJNlM5TF9WrusZWR5BO0pA44elyx7nCM 3uonn720fWwqbahirvZ0c6g3OcxE332Xn1n74J5OkRZ2g79k0nznBBg9KzJAHbuvtAah +M7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680008985; h=content-transfer-encoding:in-reply-to:organization:content-language :references:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yj+KcaJkAacnxZEaTvGU229rPcHkz6VmMv9fP22xoYc=; b=3OCUA9BSMFPj1JtdIiEDu4YYgTtqdLC4GO6Rl8eWLIAXBw3813K0Zf1b4TCRz86k7z vTFHQCcvfLyRWIuFP0CpV4VEiM8dart/uCzrtoeKYsoJKX9sXxvIbgpvjHO6ZG7UlBCM zTC0sX6mH5/u9cc9eisXDOxh9uY2c1YMFvfTLRzxLFf2QYQ3JEA9Vhe81whbsMtiAP/O w4L/zvQa8yKx7KrEIMUdfRxTK8O4BkzWIH7nrgqxqfwOZxuihh7BSJYEaLDWq1B0VNKz mGeOISTq3H//pWjtQ9YjuzA80sZ+WqWcUeCVxtOPzC7PzJG+jiPmTJ9IHieNk2UwL5F/ cFbw== X-Gm-Message-State: AO0yUKVMk/KmKT5cNkLgN3PgOpV/Xz+gDm8FwXafWIaEMzEXWrPy68aZ oizZblOoZUC5EqffBAvAwWXdOKVgLK4ofKPBoFaxqQ== X-Google-Smtp-Source: AK7set/R1Nlnz76Y1RvXnEBwxwSNZBXjFwkarY9TGGHmxSVqEH/krW/lUyXDBfpYzp2mbnoZgjgkKw== X-Received: by 2002:a4a:370f:0:b0:53b:66a3:452a with SMTP id r15-20020a4a370f000000b0053b66a3452amr7498950oor.3.1680008983503; Tue, 28 Mar 2023 06:09:43 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:60f9:1426:1d2d:d6b:1761? ([2804:1b3:a7c1:60f9:1426:1d2d:d6b:1761]) by smtp.gmail.com with ESMTPSA id i7-20020a4a8d87000000b0052a77e38722sm12590119ook.26.2023.03.28.06.09.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Mar 2023 06:09:42 -0700 (PDT) Message-ID: <74db46eb-2f06-1244-067b-12d75e38a67a@linaro.org> Date: Tue, 28 Mar 2023 10:09:39 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 From: Adhemerval Zanella Netto Subject: Re: [PATCH v2] posix: Fix some crashes in wordexp [BZ #18096] To: libc-alpha@sourceware.org, Julian Squires References: <20230318125950.3611824-1-julian@cipht.net> <20230322163957.9710-1-julian@cipht.net> Content-Language: en-US Organization: Linaro In-Reply-To: <20230322163957.9710-1-julian@cipht.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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: On 22/03/23 13:39, Julian Squires via Libc-alpha wrote: > 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 LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > 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 }, Ok, empty arithmetic expansion. > + { 0, NULL, "$[]", 0, 1, { "0", }, IFS }, > Ok, same as above (although with undocumented syntax not supported by all shells). > /* 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 }, Ok, parameter expansion. > > { 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; > } Ok.