zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Simon Guilliams <simon.guilliams@gmail.com>, zsh-workers@zsh.org
Subject: Re: Zsh - possible bug report
Date: Sun, 10 Sep 2017 17:50:26 +0100	[thread overview]
Message-ID: <20170910175026.31a421d8@ntlworld.com> (raw)
In-Reply-To: <CAPtQDzpP3pf7TkvG_fQt7SB5eHt5Wfo9COuk=2z7hRMSZ4pLHA@mail.gmail.com>

On Sun, 10 Sep 2017 15:00:28 +0200
Simon Guilliams <simon.guilliams@gmail.com> wrote:
> Hello,
> 
> I have found a behavior of zsh I cannot explain. I don't know if it is a
> bug and I hope this is not a duplicate.
> 
> $ cat print-argv0.c
> > #include <stdio.h>
> > int main(int ac, char **av)
> > {
> > if (ac > 0)
> > fputs(av[0], stdout);
> > }
> > $ cc print-argv0.c
> > $ zsh -f -c "exec -a '' ./a.out | hexdump -vC"
> > 00000000  9b 9b                                             |..|
> > 00000002
> > $ zsh -f -c "exec -a \"\" ./a.out | hexdump -vC"
> > 00000000  9c 9c                                             |..|
> > 00000002

Bug.

Thanks for the clear demonstration.

pws

diff --git a/Src/exec.c b/Src/exec.c
index 76a6bb1..e2432fd 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3007,6 +3007,9 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 		}
 		if (exec_argv0) {
 		    char *str, *s;
+		    exec_argv0 = dupstring(exec_argv0);
+		    remnulargs(exec_argv0);
+		    untokenize(exec_argv0);
 		    size_t sz = strlen(exec_argv0);
 		    str = s = zalloc(5 + 1 + sz + 1);
 		    strcpy(s, "ARGV0=");
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 0302c96..5e7d6ac 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -103,6 +103,12 @@
 0:`exec' with -a option, no space
 >/bin/SPLOOSH
 
+  (exec -a foo* $ZTST_testdir/../Src/zsh -fc 'print -r -- ${(V)0}')
+  (exec -a "" $ZTST_testdir/../Src/zsh -fc 'print -r -- ${(V)0}')
+0:rationalisation of arguments to exec -a
+>foo*
+>
+
   (
     opts=(-a /bin/WHOOOSH)
     exec $opts /bin/sh -c 'echo $0'


      reply	other threads:[~2017-09-10 16:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-10 13:00 Simon Guilliams
2017-09-10 16:50 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170910175026.31a421d8@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=simon.guilliams@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).