Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,12 @@ static bool Process_matchesFilter(const Process* this, const Table* table) {
return true;

const char* incFilter = table->incFilter;
if (incFilter && !String_contains_i(Process_getCommand(this), incFilter, true))
return true;
if (incFilter){
bool matchesCmdline = String_contains_i(Process_getCommand(this), incFilter, true);
bool matchesExePath = this->procExe && String_contains_i(this->procExe, incFilter, true);
if (!matchesCmdline && !matchesExePath)
Comment on lines +862 to +864

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 6 'String_contains_i|strcasestr' --glob 'XUtils.[ch]' .
rg -n -C 8 'Process_getCommand|mergedCommand\.str|cmdline' Process.c

Repository: htop-dev/htop

Length of output: 21238


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
text = Path('XUtils.c').read_text()
start = text.index('inline bool String_contains_i')
end = text.index('\nchar* String_cat', start)
print(text[start:end])
print("--- Process_matchesFilter context ---")
proc = Path('Process.c').read_text()
idx = proc.index('static bool Process_matchesFilter')
print(proc[idx:idx+400])
PY

web_search
NULL behavior strcasestr man page

Repository: htop-dev/htop

Length of output: 1213


Guard the nullable command before calling String_contains_i().

When this->mergedCommand.str is absent, Process_getCommand(this) returns this->cmdline, which can be NULL. String_contains_i() then passes that value to strcasestr() before line 863 can check this->procExe. Treat a missing command as a non-match, then evaluate the executable path.

Source: MCP tools

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this case can be true but it was true in current code block also.
Process_getCommand(this) was already passed straight into String_contains_i.
If this is concerning I can add another commit about this.
Please let me know @fasterit

return true;
}

const ProcessTable* pt = (const ProcessTable*) host->activeTable;
assert(Object_isA((const Object*) pt, (const ObjectClass*) &ProcessTable_class));
Expand Down