Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[bug] segfault upon empty argv[]
- X-seq: zsh-workers 48902
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [bug] segfault upon empty argv[]
- Date: Sun, 23 May 2021 07:18:21 +0100
- Archived-at: <https://zsh.org/workers/48902>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author