Source-Changes-HG archive

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

[src/netbsd-9]: src/bin/sh Pull up following revision(s) (requested by kre in...



details:   https://anonhg.NetBSD.org/src/rev/0d5c0cba4077
branches:  netbsd-9
changeset: 954371:0d5c0cba4077
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Apr 06 17:52:03 2021 +0000

description:
Pull up following revision(s) (requested by kre in ticket #1242):

        bin/sh/input.c: revision 1.72
        bin/sh/exec.c: revision 1.55

PR bin/55979

This fixes the MSAN detected reference to an unitialised variable
(an unitialised field in a struct) which happens when a command is
not found after a PATH search.
Aside from skipping some known to be going to fail exec*() calls
in some cases, the setting of the relevant field is irrelevant,
so this problem makes no practical difference to the shell, or any
shell script.

XXX (maybe) pullup -9


PR bin/55979

Correctly handle (ie: ignore completely) \0 chars (nuls) in the
shell command input stream (script, dot file, or stdin).
Previously nul chars were ignored correctly in the line in which
they occurred, but would cause trailing chars of that line to reappear
as the start of the following line.   If there was just one \0 skipped,
this would generally result in an extra \n in the sh input, which in
most cases has no effect.   With multiple \0's in a single line, more
of the end of that line was duplicated into the following one.  This
usually manifested as a weird "command not found" error.

Note that any \0 chars in the sh input make the script non-conforming,
so fixing this is not crucial (no \0's should really ever be seen) but
it was an obvious bug in the code, which was attempting to ignore nul
chars (as do many other shells), so let it be fixed.

XXX pullup -9

diffstat:

 bin/sh/exec.c  |   9 ++++++---
 bin/sh/input.c |  17 ++++++++++++++---
 2 files changed, 20 insertions(+), 6 deletions(-)

diffs (99 lines):

diff -r 4b32e92e9186 -r 0d5c0cba4077 bin/sh/exec.c
--- a/bin/sh/exec.c     Tue Apr 06 17:44:29 2021 +0000
+++ b/bin/sh/exec.c     Tue Apr 06 17:52:03 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec.c,v 1.53.2.1 2020/08/27 09:15:38 martin Exp $     */
+/*     $NetBSD: exec.c,v 1.53.2.2 2021/04/06 17:52:03 martin Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)exec.c     8.4 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: exec.c,v 1.53.2.1 2020/08/27 09:15:38 martin Exp $");
+__RCSID("$NetBSD: exec.c,v 1.53.2.2 2021/04/06 17:52:03 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -683,6 +683,7 @@
        if (act & DO_ERR)
                outfmt(out2, "%s: %s\n", name, errmsg(e, E_EXEC));
        entry->cmdtype = CMDUNKNOWN;
+       entry->u.index = idx + 1;
        return;
 
 builtin_success:
@@ -704,8 +705,10 @@
                entry->lineno = cmdp->lineno;
                entry->lno_frel = cmdp->fn_ln1;
                entry->u = cmdp->param;
-       } else
+       } else {
                entry->cmdtype = CMDUNKNOWN;
+               entry->u.index = -1;
+       }
 }
 
 
diff -r 4b32e92e9186 -r 0d5c0cba4077 bin/sh/input.c
--- a/bin/sh/input.c    Tue Apr 06 17:44:29 2021 +0000
+++ b/bin/sh/input.c    Tue Apr 06 17:52:03 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: input.c,v 1.71 2019/02/09 09:20:47 kre Exp $   */
+/*     $NetBSD: input.c,v 1.71.2.1 2021/04/06 17:52:03 martin Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c    8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.71 2019/02/09 09:20:47 kre Exp $");
+__RCSID("$NetBSD: input.c,v 1.71.2.1 2021/04/06 17:52:03 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -90,6 +90,7 @@
        int fd;                 /* file descriptor (or -1 if string) */
        int nleft;              /* number of chars left in this line */
        int lleft;              /* number of chars left in this buffer */
+       int nskip;              /* number of \0's dropped in previous line */
        const char *nextc;      /* next char in buffer */
        char *buf;              /* input buffer */
        struct strpush *strpush; /* for pushing strings at this level */
@@ -274,8 +275,13 @@
                        parselleft = parsenleft = EOF_NLEFT;
                        return PEOF;
                }
+               parsefile->nskip = 0;
        }
 
+               /* jump over slots for any \0 chars that were dropped */
+       parsenextc += parsefile->nskip;
+       parsefile->nskip = 0;
+
                /* p = (not const char *)parsenextc; */
        p = parsefile->buf + (parsenextc - parsefile->buf);
        q = p;
@@ -288,6 +294,7 @@
                switch (*p) {
                case '\0':
                        p++;    /* Skip nul */
+                       parsefile->nskip++;
                        goto check;
 
                case '\t':
@@ -306,7 +313,11 @@
                        break;
                }
 
-               *q++ = *p++;
+               if (parsefile->nskip)
+                       *q++ = *p++;
+               else
+                       q = ++p;
+
  check:
                if (--parselleft <= 0) {
                        parsenleft = q - parsenextc - 1;



Home | Main Index | Thread Index | Old Index