From e557236eda3c82028bc34c00426ff9829b4a829b Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Wed, 23 Aug 2023 14:50:48 +1000 Subject: [PATCH] Fix handling of PCP process arguments with space then slash Sync up with similar code from Linux platform, so that such processes are correctly shaded and do not trip an assert in debug builds. --- pcp/PCPProcessList.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pcp/PCPProcessList.c b/pcp/PCPProcessList.c index 7492b2c1c..69c04e221 100644 --- a/pcp/PCPProcessList.c +++ b/pcp/PCPProcessList.c @@ -288,15 +288,23 @@ static void PCPProcessList_updateCmdline(Process* process, int pid, int offset, process->isKernelThread = true; } + int tokenEnd = 0; int tokenStart = 0; + bool argSepSpace = false; + for (int i = 0; i < length; i++) { /* htop considers the next character after the last / that is before * basenameOffset, as the start of the basename in cmdline - see * Process_writeCommand */ if (command[i] == '/') tokenStart = i + 1; + /* special-case arguments for problematic situations like "find /" */ + if (command[i] <= ' ') + argSepSpace = true; } - int tokenEnd = length; + tokenEnd = length; + if (argSepSpace) + tokenStart = 0; Process_updateCmdline(process, command, tokenStart, tokenEnd); free(value.cp);