Browse Source

Disable checksum validation on wire level when fuzzing.

whitequark 7 năm trước cách đây
mục cha
commit
7bf087b8ca
4 tập tin đã thay đổi với 20 bổ sung0 xóa
  1. 5 0
      src/wire/icmpv4.rs
  2. 5 0
      src/wire/ipv4.rs
  3. 5 0
      src/wire/tcp.rs
  4. 5 0
      src/wire/udp.rs

+ 5 - 0
src/wire/icmpv4.rs

@@ -276,7 +276,12 @@ impl<T: AsRef<[u8]>> Packet<T> {
     }
 
     /// Validate the header checksum.
+    ///
+    /// # Fuzzing
+    /// This function always returns `true` when fuzzing.
     pub fn verify_checksum(&self) -> bool {
+        if cfg!(fuzzing) { return true }
+
         let data = self.buffer.as_ref();
         checksum::data(data) == !0
     }

+ 5 - 0
src/wire/ipv4.rs

@@ -233,7 +233,12 @@ impl<T: AsRef<[u8]>> Packet<T> {
     }
 
     /// Validate the header checksum.
+    ///
+    /// # Fuzzing
+    /// This function always returns `true` when fuzzing.
     pub fn verify_checksum(&self) -> bool {
+        if cfg!(fuzzing) { return true }
+
         let data = self.buffer.as_ref();
         checksum::data(&data[..self.header_len() as usize]) == !0
     }

+ 5 - 0
src/wire/tcp.rs

@@ -289,7 +289,12 @@ impl<T: AsRef<[u8]>> Packet<T> {
     /// # Panics
     /// This function panics unless `src_addr` and `dst_addr` belong to the same family,
     /// and that family is IPv4 or IPv6.
+    ///
+    /// # Fuzzing
+    /// This function always returns `true` when fuzzing.
     pub fn verify_checksum(&self, src_addr: &IpAddress, dst_addr: &IpAddress) -> bool {
+        if cfg!(fuzzing) { return true }
+
         let data = self.buffer.as_ref();
         checksum::combine(&[
             checksum::pseudo_header(src_addr, dst_addr, IpProtocol::Tcp,

+ 5 - 0
src/wire/udp.rs

@@ -104,7 +104,12 @@ impl<T: AsRef<[u8]>> Packet<T> {
     /// # Panics
     /// This function panics unless `src_addr` and `dst_addr` belong to the same family,
     /// and that family is IPv4 or IPv6.
+    ///
+    /// # Fuzzing
+    /// This function always returns `true` when fuzzing.
     pub fn verify_checksum(&self, src_addr: &IpAddress, dst_addr: &IpAddress) -> bool {
+        if cfg!(fuzzing) { return true }
+
         let data = self.buffer.as_ref();
         checksum::combine(&[
             checksum::pseudo_header(src_addr, dst_addr, IpProtocol::Udp,