Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Now that excessive use of STACKSTRNUL has served its ...



details:   https://anonhg.NetBSD.org/src/rev/c7ef19ae3f04
branches:  trunk
changeset: 824798:c7ef19ae3f04
user:      kre <kre%NetBSD.org@localhost>
date:      Mon Jun 19 02:46:50 2017 +0000

description:
Now that excessive use of STACKSTRNUL has served its purpose (well, accidental
purpose) in exposing the bug in its implementation, go back to not using
it when not needed for DEBUG TRACE purposes.   This change should have no
practical effect on either a DEBUG shell (where the STACKSTRNUL() calls
remain) or a non DEBUG shell where they are not needed.

diffstat:

 bin/sh/expand.c |  22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diffs (83 lines):

diff -r 6a72d77a9a0e -r c7ef19ae3f04 bin/sh/expand.c
--- a/bin/sh/expand.c   Mon Jun 19 02:43:55 2017 +0000
+++ b/bin/sh/expand.c   Mon Jun 19 02:46:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expand.c,v 1.117 2017/06/18 07:50:46 kre Exp $ */
+/*     $NetBSD: expand.c,v 1.118 2017/06/19 02:46:50 kre Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)expand.c   8.5 (Berkeley) 5/15/95";
 #else
-__RCSID("$NetBSD: expand.c,v 1.117 2017/06/18 07:50:46 kre Exp $");
+__RCSID("$NetBSD: expand.c,v 1.118 2017/06/19 02:46:50 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -121,6 +121,12 @@
 STATIC void add_args(struct strlist *);
 STATIC void rmescapes_nl(char *);
 
+#ifdef DEBUG
+#define        NULLTERM_4_TRACE(p)     STACKSTRNUL(p)
+#else
+#define        NULLTERM_4_TRACE(p)     do { /* nothing */ } while (/*CONSTCOND*/0)
+#endif
+
 /*
  * Expand shell variables and backquotes inside a here document.
  */
@@ -171,7 +177,7 @@
        line_number = arg->narg.lineno;
        argstr(arg->narg.text, flag);
        if (arglist == NULL) {
-               STACKSTRNUL(expdest);
+               NULLTERM_4_TRACE(expdest);
                CTRACE(DBG_EXPAND, ("expandarg: no arglist, done (%d) \"%s\"\n",
                    expdest - stackblock(), stackblock()));
                return;                 /* here document expanded */
@@ -236,13 +242,13 @@
        for (;;) {
                switch (c = *p++) {
                case '\0':
-                       STACKSTRNUL(expdest);
+                       NULLTERM_4_TRACE(expdest);
                        VTRACE(DBG_EXPAND, ("argstr returning at \"\" "
                           "added \"%s\" to expdest\n", stackblock()));
                        return p - 1;
                case CTLENDVAR: /* end of expanding yyy in ${xxx-yyy} */
                case CTLENDARI: /* end of a $(( )) string */
-                       STACKSTRNUL(expdest);
+                       NULLTERM_4_TRACE(expdest);
                        VTRACE(DBG_EXPAND, ("argstr returning at \"%.6s\"..."
                            " after %2.2X; added \"%s\" to expdest\n", 
                            p, (c&0xff), stackblock()));
@@ -277,7 +283,7 @@
                        unsigned int pos = expdest - stackblock();
 #endif
                        p = evalvar(p, (flag & ~EXP_IFS_SPLIT) | (flag & ifs_split));
-                       STACKSTRNUL(expdest);
+                       NULLTERM_4_TRACE(expdest);
                        VTRACE(DBG_EXPAND, ("argstr evalvar "
                           "added \"%s\" to expdest\n", 
                           stackblock() + pos));
@@ -290,7 +296,7 @@
 #endif
                        expbackq(argbackq->n, c & CTLQUOTE, flag);
                        argbackq = argbackq->next;
-                       STACKSTRNUL(expdest);
+                       NULLTERM_4_TRACE(expdest);
                        VTRACE(DBG_EXPAND, ("argstr expbackq added \"%s\" "
                           "to expdest\n", stackblock() + pos));
                        break;
@@ -300,7 +306,7 @@
                        unsigned int pos = expdest - stackblock();
 #endif
                        p = expari(p);
-                       STACKSTRNUL(expdest);
+                       NULLTERM_4_TRACE(expdest);
                        VTRACE(DBG_EXPAND, ("argstr expari "
                           "+ \"%s\" to expdest p=\"%.5s...\"\n",
                           stackblock() + pos, p));



Home | Main Index | Thread Index | Old Index