Commit 1272a895b2e2f105b8389f3b26ed25683e6d766c

Authored by Imanol-Mikel Barba Sabariego
1 parent 2f5eefe9

Correct handling of setuid bit when using popen

Showing 1 changed file with 6 additions and 0 deletions
check_smart/check_smart.cpp
... ... @@ -101,7 +101,13 @@ int main(int argc, char **argv)
101 101 for(int i = 1; i < argc; i++)
102 102 {
103 103 string output;
  104 + int uid = getuid();
  105 + int gid = getgid();
  106 + setuid(0);
  107 + setgid(0);
104 108 int rc = exec(command + argv[i],&output);
  109 + setuid(uid);
  110 + setgid(gid);
105 111 if(rc)
106 112 {
107 113 cout << "Error reading SMART data from disk" << endl;
... ...