Module Name:    src
Committed By:   snj
Date:           Mon Jun  5 08:15:16 UTC 2017

Modified Files:
        src/bin/sh [netbsd-8]: expand.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.110.2.1 src/bin/sh/expand.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/expand.c
diff -u src/bin/sh/expand.c:1.110 src/bin/sh/expand.c:1.110.2.1
--- src/bin/sh/expand.c:1.110	Sat Jun  3 21:52:05 2017
+++ src/bin/sh/expand.c	Mon Jun  5 08:15:16 2017
@@ -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 @@ expandarg(union node *arg, struct arglis
 	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 @@ expandarg(union node *arg, struct arglis
 	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 @@ exptilde(const char *p, int flag)
 	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 @@ exptilde(const char *p, int flag)
 			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 @@ exptilde(const char *p, int flag)
 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 @@ removerecordregions(int endoff)
 		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 @@ removerecordregions(int endoff)
 	}
 	if (ifslastp->endoff > endoff)
 		ifslastp->endoff = endoff;
+	VTRACE(DBG_EXPAND, ("->(%d,%d)", ifslastp->begoff,ifslastp->endoff));
 }
 
 
@@ -485,7 +498,7 @@ expari(const char *p, int flag)
 		;
 
 	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 @@ recordregion(int start, int end, int inq
 {
 	struct ifsregion *ifsp;
 
+	VTRACE(DBG_EXPAND, ("recordregion(%d,%d,%d)\n", start, end, inquotes));
 	if (ifslastp == NULL) {
 		ifsp = &ifsfirst;
 	} else {

Reply via email to