mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-10 22:31:24 +02:00
52515: (+ tests in 52527) avoid sh errors when running shebang-less scripts with paths starting with - or +
This commit is contained in:
parent
8c59638522
commit
b3cad1c24c
3 changed files with 34 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
|||
2024-02-18 Stephane Chazelas <stephane@chazelas.org>
|
||||
|
||||
* 52515: Src/exec.c (+ tests in 52527) avoid sh errors when
|
||||
running shebang-less scripts with paths starting with - or +
|
||||
|
||||
2024-02-17 Bart Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 52556: Src/builtin.c: fix crash when applying a type change via
|
||||
|
|
17
Src/exec.c
17
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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||