Skip to content

Commit

Permalink
Reject invalid ${#...} expansions.
Browse files Browse the repository at this point in the history
Test case:

  echo ${#bad stuff}
  • Loading branch information
hvdijk committed Sep 12, 2018
1 parent 50220f3 commit 4546fe7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/expand.c
Expand Up @@ -649,13 +649,16 @@ evalvar(char *p, int flag)
subtype = varflags & VSTYPE;

if (!subtype)
badsub:
sh_error("Bad substitution");

quoted = flag & EXP_QUOTED;
var = p;
easy = (!quoted || (*var == '@' && shellparam.nparam));
startloc = expdest - (char *)stackblock();
p = strchr(p, '=') + 1;
if (subtype == VSLENGTH && *p != (char)CTLENDVAR)
goto badsub;

again:
varlen = varvalue(var, varflags, flag);
Expand Down

0 comments on commit 4546fe7

Please sign in to comment.