public inbox for dash@vger.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Aleksander Ushakov <retes672@gmail.com>
Cc: dash@vger.kernel.org
Subject: [PATCH] parser: Catch bogus case patterns
Date: Sun, 15 Mar 2026 14:44:53 +0900	[thread overview]
Message-ID: <abZHVeTi6SS6uIaR@gondor.apana.org.au> (raw)
In-Reply-To: <CADdNFasDNSdX+krLXYqUnx8O1HF8P77SLukKJRHfZMu5OUE-gg@mail.gmail.com>

Aleksander Ushakov <retes672@gmail.com> wrote:
>
>    case $PATH in 
>        *$PWD*)
>            echo \$PWD in \$PATH
>        ;;
>        ))

This is the cause of the issue in dash, an unexpected TRP token
causes an invalid word to be inserted into the case statement.

---8<---
If the token in a case statement pattern is not a TWORD, do not
insert it into the pattern list.  Instead abort the parsing with
a syntax error.

Reported-by: Aleksander Ushakov <retes672@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/src/parser.c b/src/parser.c
index 5714958..bbee1e3 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -442,6 +442,8 @@ next_case:
 			cp->type = NCLIST;
 			app = &cp->nclist.pattern;
 			for (;;) {
+				if (lasttoken != TWORD)
+					synexpect(TWORD);
 				*app = ap = (union node *)stalloc(sizeof (struct narg));
 				ap->type = NARG;
 				ap->narg.text = wordtext;
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

      reply	other threads:[~2026-03-15  5:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-13 18:56 heap-use-after-free calcsize() src/nodes.c:174 Aleksander Ushakov
2026-03-15  5:44 ` Herbert Xu [this message]

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=abZHVeTi6SS6uIaR@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=dash@vger.kernel.org \
    --cc=retes672@gmail.com \
    /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