summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-08-25 10:57:48 +0000
committerjilles <jilles@FreeBSD.org>2013-08-25 10:57:48 +0000
commite694117f8290f6b7dcc6f1ce75442a1b359ecba6 (patch)
tree5656eb681a6691278da0665454be3466dfe79222 /bin/sh
parent6c0efad132654ea9bfc4e58975d1d58ce8d4b424 (diff)
downloadFreeBSD-src-e694117f8290f6b7dcc6f1ce75442a1b359ecba6.zip
FreeBSD-src-e694117f8290f6b7dcc6f1ce75442a1b359ecba6.tar.gz
sh: Disallow empty simple commands.
As per POSIX, a simple command must have at least one redirection, assignment word or command word. These occured in rare cases such as eval "f()" . The extension of allowing no commands inside { }, if, while, for, etc. remains.
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/parser.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index a350b8b..795e3ee 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -573,7 +573,7 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
synexpect(TEND);
checkkwd = CHKKWD | CHKALIAS;
break;
- /* Handle an empty command like other simple commands. */
+ /* A simple command must have at least one redirection or word. */
case TBACKGND:
case TSEMI:
case TAND:
@@ -581,16 +581,12 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
case TPIPE:
case TENDCASE:
case TFALLTHRU:
- /*
- * An empty command before a ; doesn't make much sense, and
- * should certainly be disallowed in the case of `if ;'.
- */
+ case TEOF:
+ case TNL:
+ case TRP:
if (!redir)
synexpect(-1);
- case TNL:
- case TEOF:
case TWORD:
- case TRP:
tokpushback++;
n1 = simplecmd(rpp, redir);
return n1;
OpenPOWER on IntegriCloud