Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Another arithmetic expansion recordregion() fix, this...



details:   https://anonhg.NetBSD.org/src/rev/6f16ddd5c3d8
branches:  trunk
changeset: 354129:6f16ddd5c3d8
user:      kre <kre%NetBSD.org@localhost>
date:      Mon Jun 05 02:15:55 2017 +0000

description:
Another arithmetic expansion recordregion() fix, this time
calculate the lenght (used to calculate the end) based upon the
correct starting point.

Thanks to John Klos for finding and reporting this one.

diffstat:

 bin/sh/expand.c |  25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)

diffs (110 lines):

diff -r fba58049997c -r 6f16ddd5c3d8 bin/sh/expand.c
--- a/bin/sh/expand.c   Mon Jun 05 01:29:21 2017 +0000
+++ b/bin/sh/expand.c   Mon Jun 05 02:15:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expand.c,v 1.111 2017/06/04 23:40:31 kre Exp $ */
+/*     $NetBSD: expand.c,v 1.112 2017/06/05 02:15:55 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.111 2017/06/04 23:40:31 kre Exp $");
+__RCSID("$NetBSD: expand.c,v 1.112 2017/06/05 02:15:55 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -159,6 +159,7 @@
        struct strlist *sp;
        char *p;
 
+       CTRACE(DBG_EXPAND, ("expandarg(fl=%#x)\n", flag));
        if (fflag)              /* no filename expandsion */
                flag &= ~EXP_GLOB;
 
@@ -169,9 +170,13 @@
        argstr(arg->narg.text, flag);
        if (arglist == NULL) {
                STACKSTRNUL(expdest);
+               CTRACE(DBG_EXPAND, ("expandarg: no arglist, done (%d) \"%s\"\n",
+                   expdest - stackblock(), stackblock()));
                return;                 /* here document expanded */
        }
        STPUTC('\0', expdest);
+       CTRACE(DBG_EXPAND, ("expandarg: arglist got (%d) \"%s\"\n",
+                   expdest - stackblock() - 1, stackblock()));
        p = grabstackstr(expdest);
        exparg.lastp = &exparg.list;
        /*
@@ -343,7 +348,7 @@
  done:
        STACKSTRNUL(user);
 
-       CTRACE(DBG_EXPAND, ("exptilde, found \"~%s\" :", expdest));
+       CTRACE(DBG_EXPAND, ("exptilde, found \"%s\" :", expdest));
        if (*expdest == '\0')
                home = lookupvar("HOME");
        else if ((pw = getpwnam(expdest)) == NULL)
@@ -368,10 +373,15 @@
 STATIC void 
 removerecordregions(int endoff)
 {
-       if (ifslastp == NULL)
+
+       VTRACE(DBG_EXPAND, ("removerecordregions(%d):", endoff));
+       if (ifslastp == NULL) {
+               VTRACE(DBG_EXPAND, (" none\n", endoff));
                return;
+       }
 
        if (ifsfirst.endoff > endoff) {
+               VTRACE(DBG_EXPAND, (" first(%d)", ifsfirst.endoff));
                while (ifsfirst.next != NULL) {
                        struct ifsregion *ifsp;
                        INTOFF;
@@ -383,15 +393,18 @@
                if (ifsfirst.begoff > endoff)
                        ifslastp = NULL;
                else {
+                       VTRACE(DBG_EXPAND,("->(%d,%d)",ifsfirst.begoff,endoff));
                        ifslastp = &ifsfirst;
                        ifsfirst.endoff = endoff;
                }
+               VTRACE(DBG_EXPAND, ("\n"));
                return;
        }
 
        ifslastp = &ifsfirst;
        while (ifslastp->next && ifslastp->next->begoff < endoff)
                ifslastp=ifslastp->next;
+       VTRACE(DBG_EXPAND, (" found(%d,%d)", ifslastp->begoff,ifslastp->endoff));
        while (ifslastp->next != NULL) {
                struct ifsregion *ifsp;
                INTOFF;
@@ -402,6 +415,7 @@
        }
        if (ifslastp->endoff > endoff)
                ifslastp->endoff = endoff;
+       VTRACE(DBG_EXPAND, ("->(%d,%d)", ifslastp->begoff,ifslastp->endoff));
 }
 
 
@@ -484,7 +498,7 @@
                ;
 
        if (quoted == 0)                        /* allow weird splitting */
-               recordregion(begoff, begoff + q - 1 - start, 0);
+               recordregion(begoff, begoff + q - 1 - expdest, 0);
        adjustment = q - expdest - 1;
        STADJUST(adjustment, expdest);
        VTRACE(DBG_EXPAND, ("expari: adding %d ed \"%.*s\", "
@@ -1106,6 +1120,7 @@
 {
        struct ifsregion *ifsp;
 
+       VTRACE(DBG_EXPAND, ("recordregion(%d,%d,%d)\n", start, end, inquotes));
        if (ifslastp == NULL) {
                ifsp = &ifsfirst;
        } else {



Home | Main Index | Thread Index | Old Index