Module Name: src
Committed By: christos
Date: Thu Aug 27 07:46:47 UTC 2015
Modified Files:
src/bin/sh: expand.c
Log Message:
PR/50179: Timo Buhrmester: sh(1) variable expansion bug
To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 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.92 src/bin/sh/expand.c:1.93
--- src/bin/sh/expand.c:1.92 Sat Jun 6 11:22:58 2015
+++ src/bin/sh/expand.c Thu Aug 27 03:46:47 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: expand.c,v 1.92 2015/06/06 15:22:58 joerg Exp $ */
+/* $NetBSD: expand.c,v 1.93 2015/08/27 07:46:47 christos 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.92 2015/06/06 15:22:58 joerg Exp $");
+__RCSID("$NetBSD: expand.c,v 1.93 2015/08/27 07:46:47 christos Exp $");
#endif
#endif /* not lint */
@@ -98,7 +98,7 @@ struct arglist exparg; /* holds expande
STATIC void argstr(char *, int);
STATIC char *exptilde(char *, int);
STATIC void expbackq(union node *, int, int);
-STATIC int subevalvar(char *, char *, int, int, int, int);
+STATIC int subevalvar(char *, char *, int, int, int, int, int);
STATIC char *evalvar(char *, int);
STATIC int varisset(char *, int);
STATIC void varvalue(char *, int, int, int);
@@ -495,7 +495,7 @@ expbackq(union node *cmd, int quoted, in
STATIC int
-subevalvar(char *p, char *str, int strloc, int subtype, int startloc, int varflags)
+subevalvar(char *p, char *str, int strloc, int subtype, int startloc, int varflags, int quotes)
{
char *startp;
char *loc = NULL;
@@ -548,10 +548,10 @@ subevalvar(char *p, char *str, int strlo
for (loc = startp; loc < str; loc++) {
c = *loc;
*loc = '\0';
- if (patmatch(str, startp, varflags & VSQUOTE))
+ if (patmatch(str, startp, quotes))
goto recordleft;
*loc = c;
- if ((varflags & VSQUOTE) && *loc == CTLESC)
+ if (quotes && *loc == CTLESC)
loc++;
}
return 0;
@@ -560,11 +560,11 @@ subevalvar(char *p, char *str, int strlo
for (loc = str - 1; loc >= startp;) {
c = *loc;
*loc = '\0';
- if (patmatch(str, startp, varflags & VSQUOTE))
+ if (patmatch(str, startp, quotes))
goto recordleft;
*loc = c;
loc--;
- if ((varflags & VSQUOTE) && loc > startp &&
+ if (quotes && loc > startp &&
*(loc - 1) == CTLESC) {
for (q = startp; q < loc; q++)
if (*q == CTLESC)
@@ -577,10 +577,10 @@ subevalvar(char *p, char *str, int strlo
case VSTRIMRIGHT:
for (loc = str - 1; loc >= startp;) {
- if (patmatch(str, loc, varflags & VSQUOTE))
+ if (patmatch(str, loc, quotes))
goto recordright;
loc--;
- if ((varflags & VSQUOTE) && loc > startp &&
+ if (quotes && loc > startp &&
*(loc - 1) == CTLESC) {
for (q = startp; q < loc; q++)
if (*q == CTLESC)
@@ -593,9 +593,9 @@ subevalvar(char *p, char *str, int strlo
case VSTRIMRIGHTMAX:
for (loc = startp; loc < str - 1; loc++) {
- if (patmatch(str, loc, varflags & VSQUOTE))
+ if (patmatch(str, loc, quotes))
goto recordright;
- if ((varflags & VSQUOTE) && *loc == CTLESC)
+ if (quotes && *loc == CTLESC)
loc++;
}
return 0;
@@ -763,7 +763,7 @@ again: /* jump here after setting a vari
STPUTC('\0', expdest);
patloc = expdest - stackblock();
if (subevalvar(p, NULL, patloc, subtype,
- startloc, varflags) == 0) {
+ startloc, varflags, quotes) == 0) {
int amount = (expdest - stackblock() - patloc) + 1;
STADJUST(-amount, expdest);
}
@@ -776,7 +776,7 @@ again: /* jump here after setting a vari
case VSQUESTION:
if (set)
break;
- if (subevalvar(p, var, 0, subtype, startloc, varflags)) {
+ if (subevalvar(p, var, 0, subtype, startloc, varflags, quotes)) {
varflags &= ~VSNUL;
/*
* Remove any recorded regions beyond