Skip to content

fix(netstat): correct dead paren check in getProcName - #969

Merged
skevetter merged 1 commit into
mainfrom
pkg-tunnel-network/netstat-getprocname-fix
Aug 9, 2026
Merged

fix(netstat): correct dead paren check in getProcName#969
skevetter merged 1 commit into
mainfrom
pkg-tunnel-network/netstat-getprocname-fix

Conversation

@devsy-app

@devsy-app devsy-app Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Package reviewed

pkg/netstat (in the pkg-tunnel-network scope: pkg/tunnel, pkg/http, pkg/inject, pkg/netstat, pkg/port). pkg/tunnel was skipped because PR #646 already touches that area.

Issue found

getProcName in pkg/netstat/netstat_util.go had dead/misleading bounds-checking code. After locating the opening paren ( (index i, already validated i >= 0), it then located the closing paren ) (index j) via bytes.LastIndex, but the follow-up guard re-checked if i < 0 instead of if j < 0:

j := bytes.LastIndex(s, []byte(")"))
if i < 0 {   // dead: i is already known >= 0 here
    return ""
}
if i > j {
    return ""
}

The "no closing paren" case was only caught indirectly by the later i > j fallback (where j == -1), leaving the explicit guard as misleading dead code that obscured the real intent.

Change

  • pkg/netstat/netstat_util.go: corrected the guard from if i < 0 to if j < 0, so the missing-close-paren case is checked explicitly and the dead check on the already-validated i is removed. No behavioral change — the fallback already returned "" for the same inputs; this makes the intent obvious and removes dead code.
  • pkg/netstat/netstat_util_test.go: added a table-driven TestGetProcName covering the previously-untested helper, including the no closing paren and reversed parens edge cases.

Verification performed

  • mkdir -p dist
  • git fetch --quiet origin main
  • task cli:format — clean (no formatting issues)
  • task cli:lint:ci — 0 new issues
  • task cli:test — passes; the only failures are the documented pre-existing pkg/git TestRepoClone* tests (stale assertion on origin/main, unrelated to this change which touches only pkg/netstat)
  • go test ./pkg/netstat/...ok, all TestGetProcName subtests pass (name in parens, no opening paren, no closing paren, reversed parens, empty name, name with parens inside)
  • No tunnel proto changes, so task cli:build:grpc was not required.

Expected effect

Removes a dead-code footgun in a parsing helper and adds the first unit tests for it, guarding the no-close-paren edge case against future regressions.

This PR was created by an AI agent as part of an automated daily package review job.

getProcName's second guard checked the already-validated open-paren index instead of the close-paren index. The close-paren-not-found case was only caught indirectly by the later i > j fallback, leaving misleading dead code. Use j < 0 to make the intent explicit, and add table-driven tests covering the previously-untested helper including the no-close-paren edge case.
@netlify

netlify Bot commented Aug 9, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 1a9f903
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6a78f72edd38fd00080a7e5c

@netlify

netlify Bot commented Aug 9, 2026

Copy link
Copy Markdown

Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 1a9f903
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6a78f72eaa29e200089a715e

@github-actions github-actions Bot added the size/s label Aug 9, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

AI Reviewer: run a review on demand. To trigger the first review automatically, go to your organization or repository integration settings. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@skevetter
skevetter marked this pull request as ready for review August 9, 2026 22:00
@skevetter
skevetter enabled auto-merge (squash) August 9, 2026 22:01
@skevetter
skevetter merged commit 73deba4 into main Aug 9, 2026
67 checks passed
@skevetter
skevetter deleted the pkg-tunnel-network/netstat-getprocname-fix branch August 9, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant