explicitly check for assumptions in api/dns.rs#6311
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR adds bounds checks to parse_caa_record and parse_naptr_record to convert panics from out-of-bounds slice indexing into proper Err returns. Since panics across CXX abort the process, this is a good hardening change.
Issues (by severity):
-
Medium:
parse_replacementhas the same class of bug. The function at line 95 doesinput[offset_index..length + offset_index]wherelengthis parsed from untrusted hex input. A malicious or malformedlengthvalue will cause a panic. Sinceparse_replacementis called fromparse_naptr_record(line 264), this is reachable from JS via the same path. The same hardening applied in this PR should be extended there:if length + offset_index > input.len() { return Err(DnsParserError::InvalidDnsResponse( "replacement data too short for declared frame length".to_owned(), )); } let subset = input[offset_index..length + offset_index].to_vec();
-
Low: Redundant check in
parse_caa_record. Thedata.len() < 2check on line 154 is technically always true whenparts.len() == 3(since the first guard already ensuredparts.len() >= 3, anddata = parts[2..]). This is defensible as defense-in-depth, so just flagging for awareness — no action needed.
|
Review posted successfully on PR #6311. Here's a summary of what I found: 1 actionable issue:
1 informational note:
|
9d844d1 to
44dbfd1
Compare
44dbfd1 to
9f698c9
Compare
9f698c9 to
b2791c6
Compare
No description provided.