Skip to content

Commit edfdb23

Browse files
authored
Merge pull request #843 from thvdveld/fix-dhcpv4-parse
fix(dhcpv4): panic when parsing address
2 parents 9a5724c + f1fc4ae commit edfdb23

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/wire/dhcpv4.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,18 @@ impl<'a> Repr<'a> {
788788
(field::OPT_DOMAIN_NAME_SERVER, _) => {
789789
let mut servers = Vec::new();
790790
const IP_ADDR_BYTE_LEN: usize = 4;
791-
for chunk in data.chunks(IP_ADDR_BYTE_LEN) {
791+
let mut addrs = data.chunks_exact(IP_ADDR_BYTE_LEN);
792+
for chunk in &mut addrs {
792793
// We ignore push failures because that will only happen
793794
// if we attempt to push more than 4 addresses, and the only
794795
// solution to that is to support more addresses.
795796
servers.push(Ipv4Address::from_bytes(chunk)).ok();
796797
}
797798
dns_servers = Some(servers);
799+
800+
if !addrs.remainder().is_empty() {
801+
net_trace!("DHCP domain name servers contained invalid address");
802+
}
798803
}
799804
_ => {}
800805
}

0 commit comments

Comments
 (0)