Module Name: src
Committed By: dsl
Date: Sat Dec 22 20:15:22 UTC 2012
Modified Files:
src/bin/sh: expand.c expand.h
Log Message:
Fix the expansion of "$(foo-$bar}" so that IFS isn't applied when
expanding $bar.
Noted by Greg Troxel on tech-userlevel running some 'git' tests.
Should fix PR bin/47361
To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/bin/sh/expand.c
cvs rdiff -u -r1.18 -r1.19 src/bin/sh/expand.h
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.87 src/bin/sh/expand.c:1.88
--- src/bin/sh/expand.c:1.87 Wed Mar 28 20:11:25 2012
+++ src/bin/sh/expand.c Sat Dec 22 20:15:22 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.c,v 1.87 2012/03/28 20:11:25 christos Exp $ */
+/* $NetBSD: expand.c,v 1.88 2012/12/22 20:15:22 dsl 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.87 2012/03/28 20:11:25 christos Exp $");
+__RCSID("$NetBSD: expand.c,v 1.88 2012/12/22 20:15:22 dsl Exp $");
#endif
#endif /* not lint */
@@ -248,7 +248,7 @@ argstr(char *p, int flag)
break;
default:
STPUTC(c, expdest);
- if (flag & EXP_IFS_SPLIT & ifs_split && strchr(ifs, c) != NULL) {
+ if (flag & ifs_split && strchr(ifs, c) != NULL) {
/* We need to get the output split here... */
recordregion(expdest - stackblock() - 1,
expdest - stackblock(), 0);
@@ -703,8 +703,21 @@ again: /* jump here after setting a vari
}
- apply_ifs = ((varflags & VSQUOTE) == 0 ||
- (*var == '@' && shellparam.nparam != 1));
+ if (flag & EXP_IN_QUOTES)
+ apply_ifs = 0;
+ else if (varflags & VSQUOTE) {
+ if (*var == '@' && shellparam.nparam != 1)
+ apply_ifs = 1;
+ else {
+ /*
+ * Mark so that we don't apply IFS if we recurse through
+ * here expanding $bar from "${foo-$bar}".
+ */
+ flag |= EXP_IN_QUOTES;
+ apply_ifs = 0;
+ }
+ } else
+ apply_ifs = 1;
switch (subtype) {
case VSLENGTH:
Index: src/bin/sh/expand.h
diff -u src/bin/sh/expand.h:1.18 src/bin/sh/expand.h:1.19
--- src/bin/sh/expand.h:1.18 Sat Jun 18 21:18:46 2011
+++ src/bin/sh/expand.h Sat Dec 22 20:15:22 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.h,v 1.18 2011/06/18 21:18:46 christos Exp $ */
+/* $NetBSD: expand.h,v 1.19 2012/12/22 20:15:22 dsl Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -56,6 +56,7 @@ struct arglist {
#define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */
#define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */
#define EXP_IFS_SPLIT 0x20 /* need to record arguments for ifs breakup */
+#define EXP_IN_QUOTES 0x40 /* don't set EXP_IFS_SPLIT again */
union node;