Skip to content

Conversation

@dogancanbakir
Copy link
Member

@dogancanbakir dogancanbakir commented Jan 5, 2026

Summary

  • Fixes bug introduced in naabu 2.3.7 and option -pf #1615
  • When using -pf with a file containing comma-separated ports on a single line, the entire line was passed as one element to parsePortsSlice, causing the error invalid port selection segment
  • This fix splits each element by comma before processing

Test plan

  • Create a ports file with comma-separated ports on a single line (e.g., 80,443,8080,22-25)
  • Run naabu -host 127.0.0.1 -pf ports.txt
  • Verify it no longer throws parsing errors
  • Existing unit tests pass

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced port specification parsing to support comma-separated segments with individual protocol settings (UDP prefix support).
    • More robust handling of edge cases and improved error messaging for invalid port values.

✏️ Tip: You can customize this high-level summary in your review settings.

When using -pf with a file containing comma-separated ports on a single line,
the entire line was passed as one element to parsePortsSlice, causing parsing
to fail. This fix splits each element by comma before processing.
@auto-assign auto-assign bot requested a review from dwisiswant0 January 5, 2026 08:32
@coderabbitai
Copy link

coderabbitai bot commented Jan 5, 2026

Walkthrough

The parsePortsSlice function in pkg/runner/ports.go has been refactored to support comma-separated port segments with per-segment protocol detection via "u:" prefix for UDP and default TCP. The parser now handles individual segments, ranges (start-end), and single ports with validation, while skipping empty segments and preserving deduplication and exclusion logic.

Changes

Cohort / File(s) Summary
Port Parser Enhancement
pkg/runner/ports.go
Reworked parsePortsSlice to process comma-separated segments with per-segment UDP/TCP protocol detection. Added support for port ranges (start-end) and single ports with 1–65535 validation. Consolidated parsing into a single per-segment flow, removing legacy handling. Preserved deduplication and port+protocol-based exclusion matching; adjusted error messages for segment context.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 The port parser once broke with files so long,
But now it handles segments all day strong,
Commas and ranges, protocols too,
UDP marked with "u:", the default is true,
Validation and dedup keep chaos at bay! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: handling comma-separated ports in the ports file parsing logic.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #1615: fixes regression, restores parsing of comma-separated values and ranges, validates port bounds, and removes the invalid segment error.
Out of Scope Changes check ✅ Passed All changes are scoped to the parsePortsSlice function to fix port file parsing and are directly related to the linked issue requirements.
✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@dogancanbakir dogancanbakir self-assigned this Jan 5, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Fix all issues with AI Agents 🤖
In @pkg/runner/ports.go:
- Around line 179-182: The single-port validation in the parsing logic
incorrectly allows port 0; update the check in the block where strconv.Atoi is
called (variable portNumber) to ensure ports are within 1–65535 (e.g., if err !=
nil || portNumber < 1 || portNumber > 65535) and return the same formatted error
when out of range so single ports are validated consistently with the range
handling.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9976c32 and d2b16af.

📒 Files selected for processing (1)
  • pkg/runner/ports.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Lint
  • GitHub Check: release-test-windows
  • GitHub Check: release-test-mac
  • GitHub Check: Functional Test (ubuntu-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
pkg/runner/ports.go (2)

142-146: LGTM! Core fix for comma-separated port parsing.

The nested split and trim logic correctly handles comma-separated ports within file lines, addressing the regression from issue #1615. Skipping empty segments gracefully handles edge cases like trailing commas.


148-152: Protocol detection logic is correct.

Per-segment UDP detection via u: prefix with TCP default is properly implemented.

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.

bug introduced in naabu 2.3.7 and option -pf

2 participants