Source-Changes-HG archive

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

[src/trunk]: src/bin/sh After bug report 262 (from 2010)



details:   https://anonhg.NetBSD.org/src/rev/d6fa59a327c6
branches:  trunk
changeset: 744514:d6fa59a327c6
user:      kre <kre%NetBSD.org@localhost>
date:      Tue Feb 04 16:06:59 2020 +0000

description:
After bug report 262 (from 2010)
        https://austingroupbugs.net/view.php?id=252
the Austin Group decided to require processing of "--" by the "."
and "exec" commands to solve a problem where some shells did
option processing for those commands (permitted) and others did
not (also permitted) which left no safe way to process a file
with a name beginning with "-".

This has finally made its way into what will be the next version of
the POSIX standard.

Since this shell did no option processing at all for those commands,
we need to update.   This is that update.

The sole effect is that a "--" 'option' (to "." or "exec") is ignored.
This means that if you want to use "--" as the arg to one of those
commands, it needs to be given twice ". -- --".   Apart from that there
should be no difference at all (though the "--" can now be used in other
situations, where we did not require it before, and still do not).

diffstat:

 bin/sh/eval.c    |  16 ++++++++++------
 bin/sh/options.c |  12 +++++++++---
 2 files changed, 19 insertions(+), 9 deletions(-)

diffs (98 lines):

diff -r 9bb63541bdc0 -r d6fa59a327c6 bin/sh/eval.c
--- a/bin/sh/eval.c     Tue Feb 04 15:06:27 2020 +0000
+++ b/bin/sh/eval.c     Tue Feb 04 16:06:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.177 2019/12/21 18:54:15 kre Exp $   */
+/*     $NetBSD: eval.c,v 1.178 2020/02/04 16:06:59 kre Exp $   */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.177 2019/12/21 18:54:15 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.178 2020/02/04 16:06:59 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1493,7 +1493,9 @@
 {
        exitstatus = 0;
 
-       if (argc >= 2) {                /* That's what SVR2 does */
+       (void) nextopt(NULL);           /* ignore a leading "--" */
+
+       if (*argptr != NULL) {          /* That's what SVR2 does */
                char *fullname;
                /*
                 * dot_funcnest needs to be 0 when not in a dotcmd, so it
@@ -1503,7 +1505,7 @@
                struct stackmark smark;
 
                setstackmark(&smark);
-               fullname = find_dot_file(argv[1]);
+               fullname = find_dot_file(*argptr);
                setinputfile(fullname, 1);
                commandname = fullname;
                dot_funcnest_old = dot_funcnest;
@@ -1649,7 +1651,9 @@
 int
 execcmd(int argc, char **argv)
 {
-       if (argc > 1) {
+       (void) nextopt(NULL);           /* ignore a leading "--" */
+
+       if (*argptr) {
                struct strlist *sp;
 
                iflag = 0;              /* exit on error */
@@ -1657,7 +1661,7 @@
                optschanged();
                for (sp = cmdenviron; sp; sp = sp->next)
                        setvareq(sp->text, VDOEXPORT|VEXPORT|VSTACK);
-               shellexec(argv + 1, environment(), pathval(), 0, 0);
+               shellexec(argptr, environment(), pathval(), 0, 0);
        }
        return 0;
 }
diff -r 9bb63541bdc0 -r d6fa59a327c6 bin/sh/options.c
--- a/bin/sh/options.c  Tue Feb 04 15:06:27 2020 +0000
+++ b/bin/sh/options.c  Tue Feb 04 16:06:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: options.c,v 1.53 2018/07/13 22:43:44 kre Exp $ */
+/*     $NetBSD: options.c,v 1.54 2020/02/04 16:06:59 kre Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)options.c  8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: options.c,v 1.53 2018/07/13 22:43:44 kre Exp $");
+__RCSID("$NetBSD: options.c,v 1.54 2020/02/04 16:06:59 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -595,7 +595,11 @@
  * Standard option processing (a la getopt) for builtin routines.  The
  * only argument that is passed to nextopt is the option string; the
  * other arguments are unnecessary.  It return the character, or '\0' on
- * end of input.
+ * end of input.  If optstring is NULL, then there are no options, and
+ * args are allowed to begin with '-', but a single leading "--" will be
+ * discarded.   This is for some POSIX special builtins that require
+ * -- processing, have no args, and we never did opt processing before
+ * and need to retain backwards compat.
  */
 
 int
@@ -613,6 +617,8 @@
                if (p[0] == '-' && p[1] == '\0')        /* check for "--" */
                        return '\0';
        }
+       if (optstring == NULL)
+               return '\0';
        c = *p++;
        for (q = optstring ; *q != c ; ) {
                if (*q == '\0')



Home | Main Index | Thread Index | Old Index