summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2009-12-30 17:16:49 +0000
committerjilles <jilles@FreeBSD.org>2009-12-30 17:16:49 +0000
commit5694a8569bd5c057cbf3a314c8bc3fab41f9b91a (patch)
treee699104a8fcafc705b9f9f08a268b84794c47115 /bin
parent979f6982f1bcfb1c1c36f34438c9090cca927e24 (diff)
downloadFreeBSD-src-5694a8569bd5c057cbf3a314c8bc3fab41f9b91a.zip
FreeBSD-src-5694a8569bd5c057cbf3a314c8bc3fab41f9b91a.tar.gz
Fix memory leak when parsing backticks (``).
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/parser.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index b1547e3..b85d10ad 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -1311,11 +1311,16 @@ parsebackq: {
int savelen;
int saveprompt;
const int bq_startlinno = plinno;
+ char *volatile ostr = NULL;
+ struct parsefile *const savetopfile = getcurrentfile();
str = NULL;
if (setjmp(jmploc.loc)) {
+ popfilesupto(savetopfile);
if (str)
ckfree(str);
+ if (ostr)
+ ckfree(ostr);
handler = savehandler;
if (exception == EXERROR) {
startlinno = bq_startlinno;
@@ -1335,13 +1340,12 @@ parsebackq: {
/* We must read until the closing backquote, giving special
treatment to some slashes, and then push the string and
reread it as input, interpreting it normally. */
- char *out;
+ char *oout;
int c;
- int savelen;
- char *str;
+ int olen;
- STARTSTACKSTR(out);
+ STARTSTACKSTR(oout);
for (;;) {
if (needprompt) {
setprompt(2);
@@ -1368,7 +1372,7 @@ parsebackq: {
}
if (c != '\\' && c != '`' && c != '$'
&& (!dblquote || c != '"'))
- STPUTC('\\', out);
+ STPUTC('\\', oout);
break;
case '\n':
@@ -1384,16 +1388,16 @@ parsebackq: {
default:
break;
}
- STPUTC(c, out);
+ STPUTC(c, oout);
}
done:
- STPUTC('\0', out);
- savelen = out - stackblock();
- if (savelen > 0) {
- str = ckmalloc(savelen);
- memcpy(str, stackblock(), savelen);
- setinputstring(str, 1);
- }
+ STPUTC('\0', oout);
+ olen = oout - stackblock();
+ INTOFF;
+ ostr = ckmalloc(olen);
+ memcpy(ostr, stackblock(), olen);
+ setinputstring(ostr, 1);
+ INTON;
}
nlpp = &bqlist;
while (*nlpp)
@@ -1435,6 +1439,12 @@ done:
str = NULL;
INTON;
}
+ if (ostr) {
+ INTOFF;
+ ckfree(ostr);
+ ostr = NULL;
+ INTON;
+ }
handler = savehandler;
if (arinest || dblquote)
USTPUTC(CTLBACKQ | CTLQUOTE, out);
OpenPOWER on IntegriCloud