diff options
author | Michael Klein <michael.klein@puffin.lb.shuttle.de> | 2015-12-02 22:15:46 +0100 |
---|---|---|
committer | Michael Klein <michael.klein@puffin.lb.shuttle.de> | 2015-12-02 22:56:01 +0100 |
commit | d18e9a4895599a479df264a6c7380b8805abb434 (patch) | |
tree | 27d10678f5540f7e3a760dbce92365edd52e7f10 /Process.c | |
parent | 670a2de6921e00e4768375b2636fa94e5ce663fd (diff) |
add some security checks when running SUID root
on Darwin, htop needs to run with root privileges to display information
about other users processes. This commit makes running htop SUID root a
bit more safe.
Diffstat (limited to 'Process.c')
-rw-r--r-- | Process.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -513,12 +513,16 @@ void Process_toggleTag(Process* this) { } bool Process_setPriority(Process* this, int priority) { - int old_prio = getpriority(PRIO_PROCESS, this->pid); - int err = setpriority(PRIO_PROCESS, this->pid, priority); - if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) { - this->nice = priority; + if ( Process_getuid == 0 || Process_getuid == (int) this->st_uid ) { + int old_prio = getpriority(PRIO_PROCESS, this->pid); + int err = setpriority(PRIO_PROCESS, this->pid, priority); + if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) { + this->nice = priority; + } + return (err == 0); } - return (err == 0); + else + return false; } bool Process_changePriorityBy(Process* this, size_t delta) { @@ -526,7 +530,8 @@ bool Process_changePriorityBy(Process* this, size_t delta) { } void Process_sendSignal(Process* this, size_t sgn) { - kill(this->pid, (int) sgn); + if ( Process_getuid == 0 || Process_getuid == (int) this->st_uid ) + kill(this->pid, (int) sgn); } long Process_pidCompare(const void* v1, const void* v2) { |