From: Harald van Dijk <harald@gigawatt.nl>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Eric Blake <eblake@redhat.com>, olof@ethup.se, dash@vger.kernel.org
Subject: Re: Parameter expansion, patterns and fnmatch
Date: Sat, 3 Sep 2016 17:16:28 +0200 [thread overview]
Message-ID: <28252930-bab6-18fd-901d-c3bb6515df4c@gigawatt.nl> (raw)
In-Reply-To: <20160903135850.GA20234@gondor.apana.org.au>
On 03/09/16 15:58, Herbert Xu wrote:
> On Sat, Sep 03, 2016 at 03:19:57PM +0200, Harald van Dijk wrote:
>>
>> But yeah, sure, if the bug has been there for over 10 years, and I'm
>> unable to find older versions of dash to check, I would have guessed
>> that dash indeed has never worked this way.
>
> OK it looks like this actually wasn't the original behaviour.
> It was introduced along with the character class support. So
> with that in mind, I feel a lot happier in changing the behaviour
> of the case statement.
>
> I've changed your patch slightly and will commit it if there are
> no other issues.
None that I can see. Agreed that avoiding increment-decrement-increment
to just do a single increment instead is an improvement, and I don't
spot any issues in it.
> ---8<---
> Subject: expand - Fix dangling left square brackets in patterns
>
> When there is an unmatched left square bracket in patterns, pmatch
> will behave strangely and exhibit undefined behaviour. This patch
> (based on Harld van Dijk's original) fixes this by treating it as
> a literal left square bracket.
>
> Reported-by: Olof Johansson <olof@ethup.se>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
>
> diff --git a/src/expand.c b/src/expand.c
> index 36bea76..2a50830 100644
> --- a/src/expand.c
> +++ b/src/expand.c
> @@ -1584,14 +1584,14 @@ pmatch(const char *pattern, const char *string)
> p++;
> }
> found = 0;
> - chr = *q++;
> + chr = *q;
> if (chr == '\0')
> return 0;
> c = *p++;
> do {
> if (!c) {
> p = startp;
> - c = *p;
> + c = '[';
> goto dft;
> }
> if (c == '[') {
> @@ -1618,6 +1618,7 @@ pmatch(const char *pattern, const char *string)
> } while ((c = *p++) != ']');
> if (found == invert)
> return 0;
> + q++;
> break;
> }
> dft: default:
>
next prev parent reply other threads:[~2016-09-03 15:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-09 9:28 Parameter expansion, patterns and fnmatch Olof Johansson
2016-08-09 21:39 ` Harald van Dijk
2016-08-17 14:50 ` Olof Johansson
2016-09-02 14:04 ` Herbert Xu
2016-09-02 14:25 ` Eric Blake
2016-09-02 14:29 ` Herbert Xu
2016-09-02 14:49 ` Eric Blake
2016-09-02 14:51 ` Herbert Xu
2016-09-03 12:03 ` Harald van Dijk
2016-09-03 13:05 ` Herbert Xu
2016-09-03 13:19 ` Harald van Dijk
2016-09-03 13:58 ` Herbert Xu
2016-09-03 15:16 ` Harald van Dijk [this message]
2016-09-02 14:46 ` Herbert Xu
2016-09-02 14:54 ` Eric Blake
2016-09-02 15:06 ` Chet Ramey
2016-09-02 14:48 ` Eric Blake
2016-09-02 15:12 ` Jilles Tjoelker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=28252930-bab6-18fd-901d-c3bb6515df4c@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=dash@vger.kernel.org \
--cc=eblake@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=olof@ethup.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).