diff --git a/BaseBin/systemhook/src/main.c b/BaseBin/systemhook/src/main.c index 14b71875e..798d34dd8 100644 --- a/BaseBin/systemhook/src/main.c +++ b/BaseBin/systemhook/src/main.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "sandbox.h" extern char **environ; @@ -216,18 +217,27 @@ int execv_hook(const char *path, char *const argv[]) return execve_hook(path, argv, environ); } -int execvp_hook(const char *file, char *const argv[]) +int execvP_hook(const char *file, const char *search_path, char *const argv[]) { - return resolvePath(file, NULL, ^int(char *path) { - return execve_hook(path, argv, environ); + __block bool execve_failed = false; + int err = resolvePath(file, search_path, ^int(char *path) { + (void)execve_hook(path, argv, environ); + execve_failed = true; + return 0; }); + if (!execve_failed) { + errno = err; + } + return -1; } -int execvP_hook(const char *file, const char *search_path, char *const argv[]) +int execvp_hook(const char *name, char * const *argv) { - return resolvePath(file, search_path, ^int(char *path) { - return execve_hook(path, argv, environ); - }); + const char *path; + /* Get the path we're searching. */ + if ((path = getenv("PATH")) == NULL) + path = _PATH_DEFPATH; + return execvP_hook(name, path, argv); }