[PATCH] parser: Catch bogus case patterns
Herbert Xu <[email protected]> Sun, 15 Mar 2026 14:44:53 +0900
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
Aleksander Ushakov <[email protected]> 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 <[email protected]> Signed-off-by: Herbert Xu <[email protected]> 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 <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt