Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/538a80670698
branches:  netbsd-8
changeset: 850696:538a80670698
user:      snj <snj%NetBSD.org@localhost>
date:      Mon Jun 05 08:15:16 2017 +0000

description:
Pull up following revision(s) (requested by kre in ticket #7):
        bin/sh/expand.c: revisions 1.111, 1.112
PR bin/52272 - fix an off-by one that broke ~ expansions.
--
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 |  28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diffs (124 lines):

diff -r e7f49b92dfd3 -r 538a80670698 bin/sh/expand.c
--- a/bin/sh/expand.c   Mon Jun 05 08:13:05 2017 +0000
+++ b/bin/sh/expand.c   Mon Jun 05 08:15:16 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expand.c,v 1.110 2017/06/03 21:52:05 kre Exp $ */
+/*     $NetBSD: expand.c,v 1.110.2.1 2017/06/05 08:15:16 snj 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.110 2017/06/03 21:52:05 kre Exp $");
+__RCSID("$NetBSD: expand.c,v 1.110.2.1 2017/06/05 08:15:16 snj 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;
        /*
@@ -321,7 +326,7 @@
        char *user;
 
        user = expdest;         /* we will just borrow top of stack */
-       while ((c = *p) != '\0') {
+       while ((c = *++p) != '\0') {
                switch(c) {
                case CTLESC:
                case CTLVAR:
@@ -339,12 +344,11 @@
                        goto done;
                }
                STPUTC(c, user);
-               p++;
        }
  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)
@@ -369,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;
@@ -384,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;
@@ -403,6 +415,7 @@
        }
        if (ifslastp->endoff > endoff)
                ifslastp->endoff = endoff;
+       VTRACE(DBG_EXPAND, ("->(%d,%d)", ifslastp->begoff,ifslastp->endoff));
 }
 
 
@@ -485,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\", "
@@ -1107,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