Skip to content

fix: harden CLI validation against panics and port overflow - #99

Merged
lance0 merged 4 commits into
masterfrom
fix/cli-validation-hardening
Jul 1, 2026
Merged

lance0 merged 4 commits into
masterfrom
fix/cli-validation-hardening

Conversation

@lance0

@lance0 lance0 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

Hardens argument and config deserialization validation to prevent panics and silent port overflow.

Changes

Testing

  • All 515 tests pass (including 11 new tests)
  • cargo clippy --all-targets -- -D warnings clean
  • New tests: NaN/inf interval/timeout rejection, port+max_ttl overflow/boundary/fixed-port, timeout boundary rejection, duration serde negative/NaN/inf/huge rejection

Risk

Low — pure validation logic, no hot-path or probe-sending changes.

lance0 added 2 commits July 1, 2026 15:05
- 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 --interval and --timeout values and add coverage for NaN/inf/huge inputs.
  • Prevent destination port wrap in UDP/TCP by validating port + max_ttl <= 65535 when per-TTL port variation is enabled.
  • Make duration_serde::deserialize non-panicking by using Duration::try_from_secs_f64 and 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 thread src/cli.rs
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
));
}
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/cli.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@lance0
lance0 merged commit 7ebfa0f into master Jul 1, 2026
6 checks passed
@lance0
lance0 deleted the fix/cli-validation-hardening branch July 1, 2026 20:53
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