Skip to content

fix(target): reject empty name in exact command-line matching - #253

Open
CJstate wants to merge 1 commit into
pranshuparmar:stagingfrom
CJstate:fix/empty-name-exact-match
Open

CJstate wants to merge 1 commit into
pranshuparmar:stagingfrom
CJstate:fix/empty-name-exact-match

Conversation

@CJstate

@CJstate CJstate commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

matchesExactToken splits each command-line argument on / (and \) and compares every segment with name. With an empty name, the first empty segment of any absolute path matches, so matchesExactToken("/usr/bin/foo", "") returned true. All four platforms call this function in exact-name resolution.

An empty name is never a valid process base name, so return false up front. Test covers an absolute path with an empty needle.

RED: the new case failed on the original function. GREEN: go test ./internal/target passes.

@pranshuparmar pranshuparmar added this to the 0.3.5 milestone Nov 21, 2026
@pranshuparmar
pranshuparmar changed the base branch from main to staging November 21, 2026 14:38

@pranshuparmar pranshuparmar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

  • The branch includes #252’s commit (0e08118, uppercase hex IDs), which we’re closing. Please rebase onto staging with only this fix, and retarget the PR to staging.
  • This only covers -x. Plain witr "" still lists every process, since every name contains the empty string.
  • An empty name is invalid input, so it should exit 4 with a clear message, but witr -x "" now exits 2 (“not found”). Rejecting it in target.Resolve covers both modes and every platform. The matcher check can stay as a backstop.

An empty target name matched every process because every name contains the
empty string. Reject it in Resolve so both plain and -x modes fail with a
clear error on every platform, and keep the matchesExactToken guard as a
backstop.

Signed-off-by: CJstate <142857225+CJstate@users.noreply.github.com>
@CJstate
CJstate force-pushed the fix/empty-name-exact-match branch from 6e9e3f4 to 39129c5 Compare November 25, 2026 04:17
@CJstate

CJstate commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Addressed all three points. Rebased onto current staging with only this fix (the #252 uppercase-hex commit is gone), and an empty name is now rejected in Resolve so both plain and -x modes exit with a clear error on every platform. The matcher guard remains as a backstop.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants