ash: [PARSER] Catch variable length expansions on non-existant specials

Upstream commit:

    Date: Thu, 30 Oct 2014 11:53:35 +0800
    [PARSER] Catch variable length expansions on non-existant specials

    Currently we only check special variable names that follow directly
    after $ or ${.  So errors such as ${#&} are not caught.  This patch
    fixes that by moving the is_special check to just before we print out
    the special variable name.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
readtoken1                                          2630    2635      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-08-14 14:23:45 +02:00
parent 647d8afe86
commit 452cc1d9bd

View File

@ -12119,7 +12119,7 @@ parsesub: {
STPUTC(c, out); STPUTC(c, out);
c = pgetc_eatbnl(); c = pgetc_eatbnl();
} while (isdigit(c)); } while (isdigit(c));
} else if (is_special(c)) { } else {
/* $[{[#]]<specialchar>[}] */ /* $[{[#]]<specialchar>[}] */
int cc = c; int cc = c;
@ -12137,10 +12137,16 @@ parsesub: {
cc = '#'; cc = '#';
} }
} }
if (!is_special(cc)) {
if (subtype == VSLENGTH)
subtype = 0;
goto badsub;
}
USTPUTC(cc, out); USTPUTC(cc, out);
} else {
goto badsub;
} }
if (c != '}' && subtype == VSLENGTH) { if (c != '}' && subtype == VSLENGTH) {
/* ${#VAR didn't end with } */ /* ${#VAR didn't end with } */
goto badsub; goto badsub;