From 4c08171ebd4395e358ec630306c1268473078046 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 3 Aug 2023 09:28:47 +0800 Subject: BSD platforms: Reject negative and zero KERN_FSCALE factors The "fscale" value, retrieved by sysctl() in BSD platforms, is used for computing CPU percentages of the processes. To prevent a division by zero, we should reject a zero "fscale" value. (A negative "fscale" value will not make sense either.) For DragonFlyBSD and FreeBSD, this would fall back to the hard-coded default scale. For NetBSD and OpenBSD, there is no hard-coded default value, so the zero or negative "fscale" is now a fatal error. Signed-off-by: Kang-Che Sung --- openbsd/OpenBSDMachine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsd') diff --git a/openbsd/OpenBSDMachine.c b/openbsd/OpenBSDMachine.c index 177e7d29..8b86dfab 100644 --- a/openbsd/OpenBSDMachine.c +++ b/openbsd/OpenBSDMachine.c @@ -99,7 +99,7 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) { OpenBSDProcessList_updateCPUcount(this); size = sizeof(this->fscale); - if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0) { + if (sysctl(fmib, 2, &this->fscale, &size, NULL, 0) < 0 || this->fscale <= 0) { CRT_fatalError("fscale sysctl call failed"); } -- cgit v1.2.3