From af0b67ccd2fb377459c05939ad2d8e0fed217bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 13 Jun 2021 11:18:12 +0200 Subject: [PATCH] FreeBSD: skip exe check for kernel thread Kernel threads do not have an executable and the check can result in garbage values as unprivileged user. --- freebsd/FreeBSDProcessList.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 407f38aa..439960bc 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -380,16 +380,15 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) { } static void FreeBSDProcessList_updateExe(const struct kinfo_proc* kproc, Process* proc) { - const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, kproc->ki_pid }; - char buffer[2048]; - size_t size = sizeof(buffer); - if (sysctl(mib, 4, buffer, &size, NULL, 0) != 0) { + if (Process_isKernelThread(proc)) { Process_updateExe(proc, NULL); return; } - /* Kernel threads return an empty buffer */ - if (buffer[0] == '\0') { + const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, kproc->ki_pid }; + char buffer[2048]; + size_t size = sizeof(buffer); + if (sysctl(mib, 4, buffer, &size, NULL, 0) != 0) { Process_updateExe(proc, NULL); return; }