Module Name: src Committed By: kre Date: Tue Feb 4 16:06:59 UTC 2020
Modified Files: src/bin/sh: eval.c options.c Log Message: 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). To generate a diff of this commit: cvs rdiff -u -r1.177 -r1.178 src/bin/sh/eval.c cvs rdiff -u -r1.53 -r1.54 src/bin/sh/options.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/eval.c diff -u src/bin/sh/eval.c:1.177 src/bin/sh/eval.c:1.178 --- src/bin/sh/eval.c:1.177 Sat Dec 21 18:54:15 2019 +++ src/bin/sh/eval.c Tue Feb 4 16:06:59 2020 @@ -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 @@ dotcmd(int argc, char **argv) { 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 @@ dotcmd(int argc, char **argv) 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 @@ truecmd(int argc, char **argv) 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 @@ execcmd(int argc, char **argv) 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; } Index: src/bin/sh/options.c diff -u src/bin/sh/options.c:1.53 src/bin/sh/options.c:1.54 --- src/bin/sh/options.c:1.53 Fri Jul 13 22:43:44 2018 +++ src/bin/sh/options.c Tue Feb 4 16:06:59 2020 @@ -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 @@ out: * 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 @@ nextopt(const char *optstring) 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')