Commit 07238f1
committed
Don't write to htoprc file if it's not owned by EUID
Because htop writes the new settings in an "atomic" fashion (that is,
create a temp file, write content and then rename the temp file to
the final name, replacing the old one), the new htoprc file could be
owned by a user that's different from the original. This can cause the
original user to not be able to access the htoprc file again.
This scenario can happen when htop is run with elevated privileges.
In Linux, this occurs when htop is run with SUID (`chmod u+s htop`).
In macOS/Darwin, this occurs when htop is run with sudo (`sudo htop`)
with the default sudoers configuration (specifically, with this
`env_keep += "HOME"` line, which is discouraged by sudo upstream).
Don't assume the htoprc file opened will be owned by the same effective
user ID. If the file's owner is different, don't write to it on htop's
exit.
Signed-off-by: Kang-Che Sung <[email protected]>1 parent 70f873e commit 07238f1
1 file changed
+4
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
335 | 337 | | |
336 | 338 | | |
337 | | - | |
| 339 | + | |
338 | 340 | | |
339 | 341 | | |
340 | 342 | | |
| |||
0 commit comments