execvpe: Execute a shell if errno == ENOEXEC
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-04-08 12:28:26 +02:00
parent eb3fb04734
commit 208fdd64ac
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -68,9 +68,21 @@ extern "C"
int err = errno;
execve(file.chars(), argv, envp);
if (errno != ENOENT && errno != EACCES) return -1;
if (errno != ENOENT && errno != EACCES && errno != ENOEXEC) return -1;
// FIXME: POSIX says that if errno == ENOEXEC, we should run /bin/sh <path>.
if (errno == ENOEXEC)
{
Vector<char*> shell_argv;
shell_argv.try_append(const_cast<char*>("sh"));
char* const* arg = argv;
do {
shell_argv.try_append(*arg);
} while (*(arg++));
execve("/bin/sh", shell_argv.data(), envp);
errno = ENOEXEC;
return -1;
}
if (err == EACCES) errno = err;
}