Skip to content

Commit

Permalink
fix(dhcpv4): panic when parsing address
Browse files Browse the repository at this point in the history
If the domain name server address list did not contain the correct amount of
bytes, then the last `chunk` was not 4 bytes long and
`Ipv4Address::from_bytes` would panic.
  • Loading branch information
thvdveld committed Sep 20, 2023
1 parent 9a5724c commit c11bd8d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/wire/dhcpv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,19 @@ 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");
}

}
_ => {}
}
Expand Down

0 comments on commit c11bd8d

Please sign in to comment.