mirror of
https://github.com/termux/termux-packages
synced 2024-06-18 17:57:08 +00:00
The getuid() root checks produces undesired behavior if this function is used instead of proper checks for file permissions whether the `/proc/stat` can be accessed or not. - If `htop` runs in fake root environments (proot/fakeroot), the getuid() function would obviously return the root user id. as a result, it will use the actual /proc/stat file and would fail in case the user does not have `/proc/stat` access. - The getuid() checks is the unreliable way of checking the permissions of `/proc/stat` file as suppose that it would always require root for checking the readability of the process status file and use it. using access() function should allow proper checks regardless of a logged user account. This change would likely replace the postinst checks of /proc/stat file and include the fake process status file in the deb package instead
37 lines
1.1 KiB
Diff
37 lines
1.1 KiB
Diff
diff -uNr htop-3.2.0/linux/LinuxProcessList.c htop-3.2.0.mod/linux/LinuxProcessList.c
|
|
--- htop-3.2.0/linux/LinuxProcessList.c 2022-05-01 14:31:20.000000000 +0800
|
|
+++ htop-3.2.0.mod/linux/LinuxProcessList.c 2022-06-18 13:46:07.415229800 +0800
|
|
@@ -274,7 +274,14 @@
|
|
this->haveSmapsRollup = (access(PROCDIR "/self/smaps_rollup", R_OK) == 0);
|
|
|
|
// Read btime (the kernel boot time, as number of seconds since the epoch)
|
|
- FILE* statfile = fopen(PROCSTATFILE, "r");
|
|
+ FILE* statfile;
|
|
+
|
|
+ if (access("/proc/stat", R_OK) == 0){
|
|
+ statfile = fopen("/proc/stat", "r");
|
|
+ } else {
|
|
+ statfile = fopen(PROCSTATFILE, "r");
|
|
+ }
|
|
+
|
|
if (statfile == NULL)
|
|
CRT_fatalError("Cannot open " PROCSTATFILE);
|
|
while (true) {
|
|
@@ -1925,7 +1932,15 @@
|
|
|
|
LinuxProcessList_updateCPUcount(super);
|
|
|
|
- FILE* file = fopen(PROCSTATFILE, "r");
|
|
+ FILE* file;
|
|
+
|
|
+ /* Read the actual procstat file only if the /proc/stat is readable by any means */
|
|
+ if (access("/proc/stat", R_OK) == 0){
|
|
+ file = fopen("/proc/stat", "r");
|
|
+ } else {
|
|
+ file = fopen(PROCSTATFILE, "r");
|
|
+ }
|
|
+
|
|
if (!file)
|
|
CRT_fatalError("Cannot open " PROCSTATFILE);
|
|
|