Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
zsh heredoc crash
- X-seq: zsh-users 21858
- From: Paulo César Pereira de Andrade <paulo.cesar.pereira.de.andrade@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: zsh heredoc crash
- Date: Fri, 9 Sep 2016 10:00:54 -0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=KJ6SJusoX7cuOiHvQzEkot++hrJ/pgF1SVfwtCiwccM=; b=kewuztsrbs+amrih8Qf4bBtsiftnUAalLQ+w1J6Im6ej0AHNK2RM+Q9SB368CQK3RH AGJ/ZwaLRELn21U11hjIunkIoNtP/1IyrrPD4PTe0lGfSOPAYL5x8vWQSvNChwmH/1FR ghvD3Qcl4vVuTmyTopEuLYk/S9QuaS1JjtBONz8UNHzUnBnvKRYstcWwGEm7H0Xxs9Wq 2MLBsK7ddEwhA1N20ZXXc1PqN8p0/Sqlpe2DOiF5GjDEgp2uS9qCFQQ9Gk4ZJxjSva6Y VYJSuwpLl6jxoD2mHtIHKrruxzVfz7y+nFFLLiFDqkFTC9eyAlg/rpCnrOh0BRJXm9Yo iZFA==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hi,
zsh (tested on 5.0.2) can be made to crash with a pattern
like this:
---8<---
#!/usr/bin/zsh
cat >> /tmp/try <<EOF
export A="$(tr '\n' ' ' <<BLDARC
content
BLDARC)"
EOF
---8<---
It will also crash with a simpler (but wrong) version:
---8<---
cat >> /tmp/try <<EOF
foo
EOF)
---8<---
With this patch:
---8<---
diff -up zsh-5.0.2/Src/exec.c.orig zsh-5.0.2/Src/exec.c
--- zsh-5.0.2/Src/exec.c.orig 2016-09-06 15:10:19.394565181 -0300
+++ zsh-5.0.2/Src/exec.c 2016-09-06 15:10:36.300551444 -0300
@@ -3631,16 +3631,16 @@ gethere(char **strp, int typ)
*bptr++ = '\n';
}
*t = '\0';
+ s = dupstring(buf);
+ zfree(buf, bsiz);
if (!qt) {
int ef = errflag;
- parsestr(buf);
+ parsestr(s);
if (!errflag)
errflag = ef;
}
- s = dupstring(buf);
- zfree(buf, bsiz);
return s;
}
---8<---
it will just print something like:
/tmp/a.sh:8: parse error
The problem is that the buf vector is allocated with
zalloc, and when calling parsestr it will call hrealloc
on the zalloc'ed buffer.
The patch just works around the crash, but a better
error message may be shown for this pattern. Ksh
allows it silently, and bash prints a warning but also
allow it.
The workaround in the script would be to not add
anything after the heredoc delimiter.
Thanks,
Paulo
Messages sorted by:
Reverse Date,
Date,
Thread,
Author