summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
authorStephane Chazelas <stephane@chazelas.org>2024-02-18 18:22:37 +0000
committerStephane Chazelas <stephane@chazelas.org>2024-02-18 18:22:37 +0000
commitb3cad1c24cb588f5b0cbb617fe6f7fc0fade11af (patch)
tree88738e89ff36aac9d80c2a887c4291db79db810b /Src
parent8c59638522d8ed06cb962d41c11d1fade27abaa9 (diff)
downloadzsh-b3cad1c24cb588f5b0cbb617fe6f7fc0fade11af.tar.gz
zsh-b3cad1c24cb588f5b0cbb617fe6f7fc0fade11af.zip
52515: (+ tests in 52527) avoid sh errors when running shebang-less scripts with paths starting with - or +
Diffstat (limited to 'Src')
-rw-r--r--Src/exec.c17
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