Repository navigation
fix: out-of-bounds panic parsing a truncated HINFO record - #499
Merged
Merged
Conversation
read_char_string read its length octet as self.data[self.offset] with no bounds check, unlike its siblings read_string, read_vec, read_ipv4 and read_ipv6, which all check first. An HINFO record whose RDATA ends exactly at the end of the message -- for instance one with RDLENGTH 0 as the last record -- leaves nothing to read there, so the index runs one byte past the packet and panics. ServiceDaemon passes socket bytes straight to DnsIncoming::new and handles only Err, not a panic, so 23 bytes from any host on the link would take down the daemon thread. It now returns an error instead. read_rr_records already treats a record error as "skip this record and re-anchor on RDLENGTH", so the malformed HINFO is dropped and the rest of the packet is still parsed. Found by fuzzing the packet parser. Co-Authored-By: Claude Opus 5 <[email protected]>
keepsimple1
added a commit
that referenced
this pull request
Sep 5, 2026
Adds cargo-fuzz scaffolding under fuzz/ and a first target, parse_packet,
covering DnsIncoming::new. ServiceDaemon hands that function the bytes it
reads off a UDP socket without inspecting them first, so every byte it
touches is reachable by any host on the link.
dns_parser is a private module, so a fuzz target -- a separate crate --
cannot call it. The new unstable-fuzz-api feature exposes src/fuzz_api.rs,
a #[doc(hidden)] module of thin wrappers, rather than widening the
visibility of dns_parser itself. It is not public API and carries no
stability guarantee.
The target checks invariants, not just the absence of panics: a parsed
message must agree with its own header counts, and must be exactly one of
a query or a response. It also renders the error of a rejected packet and
the Debug of an accepted one, since both format slices of the raw packet.
Running it needs no arguments:
cargo +nightly fuzz run parse_packet
cargo-fuzz supplies the corpus directory and artifact prefix itself. A
dictionary and an explicit -max_len were both tried and dropped: over
30-second cold starts neither moved coverage outside noise. DnsIncoming::new
has no size-dependent branch -- MAX_PKT_ABSOLUTE_IPV4 bounds the encoder,
not the parser -- so libFuzzer's default 4096-byte cap costs nothing here.
A later target that exercises to_packets would want -max_len=8972.
CI gains a fuzz job that builds the targets on nightly without running a
campaign. clippy --all-features already covers src/fuzz_api.rs, but nothing
else built fuzz/Cargo.toml or the targets, so they could break unnoticed.
The first run of this target found a remotely-triggerable panic, an HINFO
record with RDLENGTH 0 at the end of a message, fixed in #499 and covered
there by a regression test that runs on stable.
Co-Authored-By: Claude Opus 5 <[email protected]>
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.
Problem
read_char_stringread its length octet asself.data[self.offset]with no bounds check. An HINFO record whose RDATA ends exactly at the end of the message leaves no length octet to read, so the index runs one byte past the packet and panics.Fix
read_char_stringnow checks the bound and returns an error if the length byte is missing.