Repository navigation
fix: harden CLI validation against panics and port overflow - #99
Merged
Merged
Conversation
- Reject non-finite (NaN/inf) --interval and --timeout before Duration::from_secs_f64 panics (#1) - Validate destination port + max_ttl <= u16::MAX in UDP/TCP modes to prevent silent port wrap (#2) - Reject --interface early on FreeBSD/NetBSD where binding is unsupported (#7) - Tighten timeout >= 256 * interval boundary — exact equality risks sequence-wrap collision (#6) - Fix src_port overflow error message off-by-one wording (#30) - Harden duration_serde::deserialize to use try_from_secs_f64, rejecting negative/NaN/inf/out-of-range values instead of panicking on bad replay/diff JSON (#5) All 515 tests pass; clippy clean.
There was a problem hiding this comment.
Pull request overview
This PR hardens CLI argument validation and config (de)serialization to avoid startup panics and silent port overflow, aligning user input handling with runtime constraints in the probe engine.
Changes:
- Reject non-finite/invalid
--intervaland--timeoutvalues and add coverage for NaN/inf/huge inputs. - Prevent destination port wrap in UDP/TCP by validating
port + max_ttl <= 65535when per-TTL port variation is enabled. - Make
duration_serde::deserializenon-panicking by usingDuration::try_from_secs_f64and add focused tests for malformed values.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/config.rs | Switch duration deserialization to a non-panicking conversion and add tests for negative/NaN/inf/out-of-range values. |
| src/cli.rs | Strengthen CLI validation for durations, port overflow, timeout boundary, and unsupported interface binding on FreeBSD/NetBSD; add regression tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+316
to
+332
| // Validate destination port + max_ttl doesn't overflow u16 (UDP/TCP modes) | ||
| // The engine sends probes to ports base_port..base_port+max_ttl (unless --fixed-port) | ||
| let protocol = self.protocol.to_lowercase(); | ||
| let uses_port = matches!(protocol.as_str(), "udp" | "tcp") | ||
| || (protocol == "auto" && self.port.is_some()); | ||
| if uses_port && !self.port_fixed { | ||
| let base = self.port.unwrap_or(33434) as u32; | ||
| let max_dst_port = base + self.max_ttl as u32; | ||
| if max_dst_port > u16::MAX as u32 { | ||
| return Err(format!( | ||
| "port ({}) + max-ttl ({}) would use port {} (max 65535); use --fixed-port or lower --port", | ||
| self.port.unwrap_or(33434), | ||
| self.max_ttl, | ||
| max_dst_port | ||
| )); | ||
| } | ||
| } |
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.
Summary
Hardens argument and config deserialization validation to prevent panics and silent port overflow.
Changes
--intervaland--timeoutbeforeDuration::from_secs_f64panics at startupport + max_ttl <= u16::MAXin UDP/TCP modes to prevent silent port wrap (probes sent to wrong ports)duration_serde::deserializeto usetry_from_secs_f64, rejecting negative/NaN/inf/out-of-range values instead of panicking on malformed replay/diff JSONEnterandqas alternative keys to close the "Hop Detail" dialog in the TUI. #6 (medium): Tighten timeout boundary from>to>=—timeout == 256 * intervalrisks sequence-wrap collision--interfaceearly on FreeBSD/NetBSD where binding is unsupported (was accepted at validation but failed on every send)flows - 1)Testing
cargo clippy --all-targets -- -D warningscleanRisk
Low — pure validation logic, no hot-path or probe-sending changes.