Skip to content

Commit

Permalink
Improve accuracy of execvp / execvP reimplementations
Browse files Browse the repository at this point in the history
  • Loading branch information
opa334 committed Oct 20, 2023
1 parent c108748 commit cf80e83
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions BaseBin/systemhook/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <dlfcn.h>
#include <sys/sysctl.h>
#include <sys/stat.h>
#include <paths.h>
#include "sandbox.h"
extern char **environ;

Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit cf80e83

Please sign in to comment.