From aaa091f23b5d3d97082133eacdabbe2a5b61cd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Jan 2024 15:22:26 +0800 Subject: [PATCH] Terminal (Linux): fix segfault --- src/detection/terminalshell/terminalshell_linux.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 32ded8311..1224e14ea 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -312,7 +312,11 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv) { - pid_t pid = (pid_t) strtol(getenv(pidEnv), NULL, 10); + const char* envStr = getenv(pidEnv); + if (envStr == NULL) + return false; + + pid_t pid = (pid_t) strtol(envStr, NULL, 10); result->pid = (uint32_t) pid; char name[256]; if (getProcessNameAndPpid(pid, name, (pid_t*) &result->ppid, NULL) == NULL)