zsh-users
 help / color / mirror / code / Atom feed
* zsh heredoc crash
@ 2016-09-09 13:00 Paulo César Pereira de Andrade
  2016-09-09 14:33 ` Kamil Dudka
  0 siblings, 1 reply; 3+ messages in thread
From: Paulo César Pereira de Andrade @ 2016-09-09 13:00 UTC (permalink / raw)
  To: zsh-users

  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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: zsh heredoc crash
  2016-09-09 13:00 zsh heredoc crash Paulo César Pereira de Andrade
@ 2016-09-09 14:33 ` Kamil Dudka
  2016-09-09 16:35   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Kamil Dudka @ 2016-09-09 14:33 UTC (permalink / raw)
  To: Paulo César Pereira de Andrade; +Cc: zsh-users

On Friday, September 09, 2016 10:00:54 Paulo César Pereira de Andrade wrote:
>   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<---

I was not able to make upstream zsh 5.0.2 crash with the above reproducer.

The bug seems to be introduced with the following commit:

https://sourceforge.net/p/zsh/code/ci/c0d01a6f

... and fixed with the following commit:

https://sourceforge.net/p/zsh/code/ci/c6c9f5da

Kamil


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: zsh heredoc crash
  2016-09-09 14:33 ` Kamil Dudka
@ 2016-09-09 16:35   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2016-09-09 16:35 UTC (permalink / raw)
  To: zsh-users

On Fri, 9 Sep 2016 16:33:19 +0200
Kamil Dudka <kdudka@redhat.com> wrote:
> On Friday, September 09, 2016 10:00:54 Paulo César Pereira de Andrade wrote:
> > ---8<---
> > #!/usr/bin/zsh
> > 
> > cat >> /tmp/try <<EOF
> > export A="$(tr '\n' ' ' <<BLDARC
> > content
> > BLDARC)"
> > EOF
> > ---8<---
> 
> I was not able to make upstream zsh 5.0.2 crash with the above reproducer.
> 
> The bug seems to be introduced with the following commit:
> 
> https://sourceforge.net/p/zsh/code/ci/c0d01a6f
> 
> ... and fixed with the following commit:
> 
> https://sourceforge.net/p/zsh/code/ci/c6c9f5da

That's the underlying bug Paulo is talking about, yes
(zsh-workers/34322).

pws


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-09 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-09 13:00 zsh heredoc crash Paulo César Pereira de Andrade
2016-09-09 14:33 ` Kamil Dudka
2016-09-09 16:35   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).