From 5fbe9702a191169cc259de7010c766e8a4c222f6 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 1 Feb 2021 12:36:27 -0500 Subject: set PATH to reasonable default before executing SUID wrapper --- privexec/privexec.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/privexec/privexec.c b/privexec/privexec.c index 4e3816c..11b14da 100644 --- a/privexec/privexec.c +++ b/privexec/privexec.c @@ -1,9 +1,16 @@ #define _POSIX_C_SOURCE 200809L +#include #include #include +#include #include +#include #include +#ifndef ARG_MAX +#define ARG_MAX _POSIX_ARG_MAX +#endif + #ifndef PATH_CHECK #define PATH_CHECK "/usr/local/lib/privexec/check" #endif @@ -12,6 +19,10 @@ #define PATH_EXEC "/usr/local/lib/privexec/exec" #endif +#ifndef DEFAULT_PATH +#define DEFAULT_PATH "/bin:/usr/bin" +#endif + static int exec_with_privileges(char *argv[]) { argv[0] = PATH_EXEC; @@ -64,6 +75,12 @@ int main(int argc, char *argv[]) } if (check_privileges(argv) == 0) { + char path[ARG_MAX]; + if (confstr(_CS_PATH, path, sizeof(path)) < 1) { + strcpy(path, DEFAULT_PATH); + } + setenv("PATH", path, 1); + return exec_with_privileges(argv); } -- cgit v1.2.1