fix: split comma-separated targets from -l file and stdin input (#859)#954
fix: split comma-separated targets from -l file and stdin input (#859)#954CharlesWong wants to merge 1 commit intoprojectdiscovery:mainfrom
Conversation
…ectdiscovery#859) The -u flag splits comma-separated targets via goflags, but -l (file) and stdin inputs were read line-by-line without splitting. This caused lines like '192.168.1.0/24,192.168.2.0/24' to be treated as a single target, resulting in connection errors. Changes: - Add splitInputEntries() helper that splits on commas, trims whitespace, and filters empty entries - Apply splitting to file input (-l), stdin, and -u inputs (safety net) - Increase scanner buffer to 4MB for long comma-separated lines - Add scanner.Err() checks for file and stdin reads - Add comprehensive unit tests for splitInputEntries (8 cases) Fixes projectdiscovery#859
WalkthroughExtended scanner input handling to support comma-separated entries across all input sources: command-line options, files, and stdin. Introduced Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes #859 — the
-l(file) and stdin inputs read lines verbatim without splitting on commas, causing entries like192.168.1.0/24,192.168.2.0/24to be treated as a single invalid target.Root Cause
The
-uflag usesgoflags.CommaSeparatedStringSliceOptionswhich auto-splits commas, butnormalizeAndQueueInputs()feeds file/stdin lines directly toprocessInputItem()without splitting.Why This PR
I reviewed all existing approaches to this issue and combined the best ideas into a single, comprehensive fix:
splitInputEntries()— no code duplicationmaxInputScanTokenSizefor long comma-separated linesscanner.Err()checked for both file and stdin-u,-l, stdin-l, missing stdinChanges
internal/runner/runner.gosplitInputEntries()helper — splits on commas, trims whitespace, filters empty entries-uinputs (safety net),-lfile, and stdinmaxInputScanTokenSize) for long comma-separated linesscanner.Err()checks for file and stdin reads to surface I/O errorsinternal/runner/runner_test.gosplitInputEntries: single entry, comma-separated, spaces, empty entries, empty string, only delimiters, host:port, mixed hosts+CIDRsTesting