From a05e78f5318325e7d2f01bf4b8a0f11b8cf71371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 18 Apr 2021 15:49:45 +0200 Subject: [PATCH] Linux: use more robust pid parsing Also add comment to condition --- linux/LinuxProcessList.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 4564f8e6..f5a35193 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1292,11 +1292,16 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ } // filename is a number: process directory - int pid = atoi(name); - - if (pid <= 0) - continue; + int pid; + { + char* endptr; + unsigned long parsedPid = strtoul(name, &endptr, 10); + if (parsedPid == 0 || parsedPid == ULONG_MAX || *endptr != '\0') + continue; + pid = parsedPid; + } + // Skip task directory of main thread if (parent && pid == parent->pid) continue;