Module Name: src Committed By: kre Date: Wed Jun 1 02:47:05 UTC 2016
Modified Files: src/bin/sh: parser.c Log Message: PR bin/51145 PR bin/48489 More fixes to the shell parser to prevent empty simple commands (where empty means no significant text at all) - as discussed on tech-userlevel this still allows { } (which can be useful in function definitions, not really anywhere else though) except in posix mode. ( ) now generates a syntax error, as should any other place where commands are required but nothing is present. (nb, redirections, var assignments, even var expansions that expand to nothing, are all OK, and avoid the error - just comments, or whits space, are not.) This is (aside from allowing { } at all) all in accordance with the posix spec. To generate a diff of this commit: cvs rdiff -u -r1.119 -r1.120 src/bin/sh/parser.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/parser.c diff -u src/bin/sh/parser.c:1.119 src/bin/sh/parser.c:1.120 --- src/bin/sh/parser.c:1.119 Mon May 9 20:36:07 2016 +++ src/bin/sh/parser.c Wed Jun 1 02:47:05 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.119 2016/05/09 20:36:07 kre Exp $ */ +/* $NetBSD: parser.c,v 1.120 2016/06/01 02:47:05 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #else -__RCSID("$NetBSD: parser.c,v 1.119 2016/05/09 20:36:07 kre Exp $"); +__RCSID("$NetBSD: parser.c,v 1.120 2016/06/01 02:47:05 kre Exp $"); #endif #endif /* not lint */ @@ -488,12 +488,16 @@ TRACE(("expecting DO got %s %s\n", tokna n1->type = NSUBSHELL; n1->nredir.n = list(0, 0); n1->nredir.redirect = NULL; + if (n1->nredir.n == NULL) + synexpect(-1, 0); if (readtoken() != TRP) synexpect(TRP, 0); checkkwd = 1; break; case TBEGIN: n1 = list(0, 0); + if (posix && n1 == NULL) + synexpect(-1, 0); if (readtoken() != TEND) synexpect(TEND, 0); checkkwd = 1; @@ -620,6 +624,9 @@ simplecmd(union node **rpp, union node * break; } } + + if (args == NULL && redir == NULL) + synexpect(-1, 0); *app = NULL; *rpp = NULL; n = stalloc(sizeof(struct ncmd));