Bläddra i källkod

Merge pull request #843 from thvdveld/fix-dhcpv4-parse

fix(dhcpv4): panic when parsing address
Thibaut Vandervelden 1 år sedan
förälder
incheckning
edfdb23243
1 ändrade filer med 6 tillägg och 1 borttagningar
  1. 6 1
      src/wire/dhcpv4.rs

+ 6 - 1
src/wire/dhcpv4.rs

@@ -788,13 +788,18 @@ impl<'a> Repr<'a> {
                 (field::OPT_DOMAIN_NAME_SERVER, _) => {
                     let mut servers = Vec::new();
                     const IP_ADDR_BYTE_LEN: usize = 4;
-                    for chunk in data.chunks(IP_ADDR_BYTE_LEN) {
+                    let mut addrs = data.chunks_exact(IP_ADDR_BYTE_LEN);
+                    for chunk in &mut addrs {
                         // We ignore push failures because that will only happen
                         // if we attempt to push more than 4 addresses, and the only
                         // solution to that is to support more addresses.
                         servers.push(Ipv4Address::from_bytes(chunk)).ok();
                     }
                     dns_servers = Some(servers);
+
+                    if !addrs.remainder().is_empty() {
+                        net_trace!("DHCP domain name servers contained invalid address");
+                    }
                 }
                 _ => {}
             }