termux-packages/packages/htop/root-actual-procstat-file.patch
marcusz 67e641ab34
htop: add checks if a user is rooted (#10357)
There are some users have root access but they don't have read access
to /proc/stat if not into root context which in this case for SELinux
enforced devices and during the postinst step it will still check the
file unprivileged
2022-04-27 20:19:20 +08:00

21 lines
629 B
Diff

diff -uNr htop-3.1.2/linux/LinuxProcessList.c htop-3.1.2.mod/linux/LinuxProcessList.c
--- htop-3.1.2/linux/LinuxProcessList.c 2021-11-30 01:03:21.000000000 +0000
+++ htop-3.1.2.mod/linux/LinuxProcessList.c 2022-04-27 07:36:29.194907488 +0000
@@ -1898,7 +1898,15 @@
LinuxProcessList_updateCPUcount(super);
- FILE* file = fopen(PROCSTATFILE, "r");
+ FILE* file;
+
+ /* Read the actual procstat file only if we're rooted */
+ if (getuid() == 0){
+ file = fopen("/proc/stat", "r");
+ } else {
+ file = fopen(PROCSTATFILE, "r");
+ }
+
if (!file)
CRT_fatalError("Cannot open " PROCSTATFILE);