Repository navigation
XUtils: add NULL pointer guard in String_contains_i - #2152
EswaraValli wants to merge 1 commit into
Conversation
On Darwin/macOS and Linux, Process_getCommand() can legitimately return NULL for certain processes or threads. When an incremental filter is active, this NULL pointer can reach String_contains_i(), which previously passed it to strcasestr() and caused a segmentation fault. Add an early NULL guard to prevent the crash. Verified with external regression harnesses covering NULL inputs and normal single- and multi-needle matching. Fixes: htop-dev#1864 Assisted-by: Antigravity (Google DeepMind) Signed-off-by: Eswara Valli <killadaeswaravalli@gmail.com>
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
|
Thanks for bringing this up to the top of the stack again. |
Summary
Fixes: #1864
In issue #1864, a segmentation fault (Signal 11) occurred on macOS during process table filtering:
While the exact user action that activated the filter in the reported incident is unknown (e.g. interactive
F4filter entry vs.-Fcommand-line flag), the backtrace establishes that an incremental filter was active when the crash occurred (Process_rowMatchesFilteronly invokesString_contains_iwhentable->incFilteris non-NULL).On Darwin/macOS (such as unnamed threads or unpopulated
commentries) and Linux (kernel threads and zombies),Process_getCommand()can legitimately returnNULL.String_contains_i()previously passeds1directly tostrcasestr(), causing an immediate crash when encountering a NULL command.Fix
Add an early guard at the beginning of
String_contains_i():If either the haystack or needle is
NULL, the function safely returnsfalse. InProcess_matchesFilter(),!String_contains_i(...)evaluates totrue, correctly filtering out the entry without crashing.Verification
XUtils.oacross 9 regression test cases in an external test harness covering NULL haystacks, NULL needles, both pointers NULL, single/multi-needle matching, and multi-needle NULL permutations (unpatched failed 5/9 cases with SIGSEGV; patched passed 9/9).Process.o+XUtils.owith mock unnamed thread entries (proc.cmdline = NULL), confirming graceful filtering without crashing.git diff --check,./check-pcp-style.sh, andmake checkpass with zero warnings or errors.