Skip to content

Commit

Permalink
ndsudo setuid before looking for command (netdata#18189)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 committed Jul 17, 2024
1 parent 35ee129 commit e908d3b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/collectors/plugins.d/ndsudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ int main(int argc, char *argv[]) {
char new_path[] = "PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
putenv(new_path);

setuid(0);
setgid(0);
setegid(0);

bool found = false;
char filename[FILENAME_MAX];

Expand Down Expand Up @@ -429,10 +433,6 @@ int main(int argc, char *argv[]) {
exit(0);
}
else {
setuid(0);
setgid(0);
setegid(0);

char *clean_env[] = {NULL};
execve(filename, params, clean_env);
perror("execve"); // execve only returns on error
Expand Down

0 comments on commit e908d3b

Please sign in to comment.