Fix crash when a process's ps arguments string is empty - #1
Merged
Conversation
ProcessDetails.executable force-indexed the result of splitting the arguments string, which traps on an out-of-bounds access when the string is empty rather than degrading gracefully like the rest of the scanning pipeline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ProcessDetails.executableforce-indexedarguments.split(separator: " ")[0], which traps (fatal error, not a catchable Swift error) whenargumentsis empty — confirmed by running the split in isolation.Currently unreachable in practice only because
PsParser.parsehappens to never produce an emptyargumentsstring (its ownfields.count >= 5guard enforces that indirectly) — butProcessDetailsis a public type with a public initializer that doesn't itself validatearguments, so any other caller constructing one directly and reading.executablewould crash.Fix
Guard the split result instead of force-indexing; return
""for empty input, matching the rest of the codebase's degrade-don't-crash convention (documented in CLAUDE.md).Test plan
testEmptyArgumentsDoesNotCrash, which would have crashed the whole test binary on the old code (fatal traps aren't catchable) — the fix's guard makes it pass cleanly.