* [bug] segfault upon empty argv[]
@ 2021-05-23 6:18 Stephane Chazelas
0 siblings, 0 replies; only message in thread
From: Stephane Chazelas @ 2021-05-23 6:18 UTC (permalink / raw)
To: Zsh hackers list
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-05-23 6:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-23 6:18 [bug] segfault upon empty argv[] Stephane Chazelas
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).