zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [bug] segfault upon empty argv[]
Date: Sun, 23 May 2021 07:18:21 +0100	[thread overview]
Message-ID: <20210523061821.tsqq4p3saux477yg@chazelas.org> (raw)

Running zsh with an empty argv[] (not even argv[0]), here using perl:

$ echo 'echo "$0"' | strace -e execve perl -e 'exec { "./Src/zsh" } ()'
execve("/usr/bin/perl", ["/usr/bin/perl", "-e", "exec { \"./Src/zsh\" } ()"], 0x565047233358 /* 51 vars */) = 0
execve("./Src/zsh", [], 0x561425bbf300 /* 51 vars */) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=NULL} ---
+++ killed by SIGSEGV (core dumped) +++
zsh: done                              echo 'echo "$0"' |
zsh: segmentation fault (core dumped)  strace -e execve perl -e 'exec { "./Src/zsh" } ()'

(gdb) bt
#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00005555555bb72d in init_jobs (argv=0x7fffffffde98, envp=0x7fffffffdea0) at jobs.c:2035
#2  0x00005555555b5102 in zsh_main (argc=0, argv=0x7fffffffde98) at init.c:1722
#3  0x000055555556bd65 in main (argc=0, argv=0x7fffffffde98) at ./main.c:93

To be fair, few shells (or other utilities) handle that
pathological case.

bash, mksh do and their $0 expands to bash, mksh respectively
(regardless of the basename of the interpreter being executed
which means bash is not running in sh mode when /bin/sh is
executed for instance, but that's fine as argv[0] is not sh and
doesn't end in /sh anyway and there's no portable way that I
know to get the path by which you've been executed).

And dash:

$ echo 'echo "${0-unset}"' | perl -e 'exec { "dash" } ()'
unset
$ echo 'echo "${0-unset"' | perl -e 'exec { "dash" } ()'
sh: 2: Syntax error: Unterminated quoted string

($0 unset but name falls back to "sh" in error messages at
least)

-- 
Stephane


                 reply	other threads:[~2021-05-23  6:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210523061821.tsqq4p3saux477yg@chazelas.org \
    --to=stephane@chazelas.org \
    --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).