execvpe: Execute a shell if errno == ENOEXEC
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
eb3fb04734
commit
208fdd64ac
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user