From 61f8c4b0f0c6c81bd5acf541d7f9a53b392c863f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 26 Feb 2024 03:04:12 +0000 Subject: [PATCH] Add debug checks that we don't leave data behind after an RR --- src/rr.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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()); -- 2.39.5