NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/50179: sh(1) variable expansion bug
The following reply was made to PR bin/50179; it has been noted by GNATS.
From: Timo Buhrmester <fstd.lkml%gmail.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: bin/50179: sh(1) variable expansion bug
Date: Thu, 27 Aug 2015 03:19:02 +0200
--pf9I7BMVVzbSWLtt
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
> >Fix:
> None known so far.
Okay, FreeBSD fixed this in 2010, see https://lists.freebsd.org/pipermail/svn-src-head/2010-October/021986.html
Attached is the same patch, processed to apply cleanly against our sh(1).
It Fixes The Problem(TM) for me, on a first glance. Have not yet run any atf-tests, though.
Timo Buhrmester
--pf9I7BMVVzbSWLtt
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="sh.nb.patch"
--- bin/sh/expand.c.orig
+++ bin/sh/expand.c
@@ -98,7 +98,7 @@ struct arglist exparg; /* holds expanded arg list */
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, int flag)
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 strloc, int subtype, int startloc, int varfla
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 strloc, int subtype, int startloc, int varfla
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 strloc, int subtype, int startloc, int varfla
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 strloc, int subtype, int startloc, int varfla
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 variable with ${var=text} */
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 variable with ${var=text} */
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
--pf9I7BMVVzbSWLtt--
Home |
Main Index |
Thread Index |
Old Index