diff options
| author | Bart Schaefer <schaefer@zsh.org> | 2024-02-18 10:32:07 -0800 |
|---|---|---|
| committer | Bart Schaefer <schaefer@zsh.org> | 2024-02-18 10:32:07 -0800 |
| commit | c2cf21c8f012db611bab1c92ee68e8af9d09fb65 (patch) | |
| tree | b797e31eb6ba1c3d4d730a526a49be60e245f9e9 /Src/exec.c | |
| parent | 52556: regression test for unset referent (left out of last commit) (diff) | |
| parent | 52515: (+ tests in 52527) avoid sh errors when running shebang-less scripts w... (diff) | |
| download | zsh-c2cf21c8f012db611bab1c92ee68e8af9d09fb65.tar zsh-c2cf21c8f012db611bab1c92ee68e8af9d09fb65.tar.gz zsh-c2cf21c8f012db611bab1c92ee68e8af9d09fb65.tar.bz2 zsh-c2cf21c8f012db611bab1c92ee68e8af9d09fb65.tar.lz zsh-c2cf21c8f012db611bab1c92ee68e8af9d09fb65.tar.xz zsh-c2cf21c8f012db611bab1c92ee68e8af9d09fb65.tar.zst zsh-c2cf21c8f012db611bab1c92ee68e8af9d09fb65.zip | |
Merge branch 'master' of git://git.code.sf.net/p/zsh/code
Diffstat (limited to 'Src/exec.c')
| -rw-r--r-- | Src/exec.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Src/exec.c b/Src/exec.c index 7d8135266..9c8bbb458 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -612,9 +612,22 @@ zexecve(char *pth, char **argv, char **newenvp) } } if (!isbinary) { - argv[-1] = "sh"; + char** args = argv; + if (argv[0][0] == '-' || argv[0][0] == '+') { + /* + * guard against +foo or -bar script paths being + * taken as options. POSIX says the script path + * must be passed as an *operand*. "--" would also + * make sure the next argument is treated as an + * operand with POSIX compliant sh implementations + * but "-" is more portable (to the Bourne shell in + * particular) and shorter. + */ + *--args = "-"; + } + *--args = "sh"; winch_unblock(); - execve("/bin/sh", argv - 1, newenvp); + execve("/bin/sh", args, newenvp); } } } else |
