From: Matt Corallo Date: Mon, 26 Feb 2024 03:04:12 +0000 (+0000) Subject: Add debug checks that we don't leave data behind after an RR X-Git-Tag: v0.5.4~48 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=61f8c4b0f0c6c81bd5acf541d7f9a53b392c863f;p=dnssec-prover Add debug checks that we don't leave data behind after an RR --- diff --git a/src/rr.rs b/src/rr.rs index 86f5a80..33fdb18 100644 --- a/src/rr.rs +++ b/src/rr.rs @@ -261,6 +261,7 @@ impl StaticRecord for Txt { parsed_data.extend_from_slice(&data[..len]); data = &data[len..]; } + debug_assert!(data.is_empty()); Ok(Txt { name, data: parsed_data }) } fn write_u16_len_prefixed_data(&self, out: &mut Vec) { @@ -349,7 +350,9 @@ impl StaticRecord for CName { self.name.0, self.canonical_name.0) } fn read_from_data(name: Name, mut data: &[u8], wire_packet: &[u8]) -> Result { - Ok(CName { name, canonical_name: read_wire_packet_name(&mut data, wire_packet)? }) + let res = CName { name, canonical_name: read_wire_packet_name(&mut data, wire_packet)? }; + debug_assert!(data.is_empty()); + Ok(res) } fn write_u16_len_prefixed_data(&self, out: &mut Vec) { let len: u16 = name_len(&self.canonical_name); @@ -378,7 +381,9 @@ impl StaticRecord for DName { self.name.0, self.delegation_name.0) } fn read_from_data(name: Name, mut data: &[u8], wire_packet: &[u8]) -> Result { - Ok(DName { name, delegation_name: read_wire_packet_name(&mut data, wire_packet)? }) + let res = DName { name, delegation_name: read_wire_packet_name(&mut data, wire_packet)? }; + debug_assert!(data.is_empty()); + Ok(res) } fn write_u16_len_prefixed_data(&self, out: &mut Vec) { let len: u16 = name_len(&self.delegation_name); @@ -665,7 +670,9 @@ impl StaticRecord for NS { format!("{{\"type\":\"ns\",\"name\":\"{}\",\"ns\":\"{}\"}}", self.name.0, self.name_server.0) } fn read_from_data(name: Name, mut data: &[u8], wire_packet: &[u8]) -> Result { - Ok(NS { name, name_server: read_wire_packet_name(&mut data, wire_packet)? }) + let res = NS { name, name_server: read_wire_packet_name(&mut data, wire_packet)? }; + debug_assert!(data.is_empty()); + Ok(res) } fn write_u16_len_prefixed_data(&self, out: &mut Vec) { out.extend_from_slice(&name_len(&self.name_server).to_be_bytes());