Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh PR bin/51145 PR bin/48489



details:   https://anonhg.NetBSD.org/src/rev/c9f29a749475
branches:  trunk
changeset: 815709:c9f29a749475
user:      kre <kre%NetBSD.org@localhost>
date:      Wed Jun 01 02:47:05 2016 +0000

description:
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.

diffstat:

 bin/sh/parser.c |  11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diffs (45 lines):

diff -r 640dd4e7a061 -r c9f29a749475 bin/sh/parser.c
--- a/bin/sh/parser.c   Wed Jun 01 02:37:55 2016 +0000
+++ b/bin/sh/parser.c   Wed Jun 01 02:47:05 2016 +0000
@@ -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 @@
                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 @@
                        break;
                }
        }
+
+       if (args == NULL && redir == NULL)
+               synexpect(-1, 0);
        *app = NULL;
        *rpp = NULL;
        n = stalloc(sizeof(struct ncmd));



Home | Main Index | Thread Index | Old Index