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
This commit is contained in:
marcusz 2022-04-27 20:19:20 +08:00 committed by GitHub
parent fb78302c57
commit 67e641ab34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Interactive process viewer for Linux"
TERMUX_PKG_LICENSE="GPL-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=3.1.2
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://github.com/htop-dev/htop/archive/${TERMUX_PKG_VERSION}/htop-${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=fe9559637c8f21f5fd531a4c072048a404173806acbdad1359c6b82fd87aa001
# htop checks setlocale() return value for UTF-8 support, so use libandroid-support.

View File

@ -0,0 +1,20 @@
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);