dhcp: distinguish malformed and truncated options

This patch distinguishes malformed DHCP options from truncated ones.
Previously, the malformed_options field was never set and parsing errors in
overloaded file and sname fields were silently discarded.
This caused malformed options to be reported as truncated or not reported at all.

Classify errors in the primary option stream and overloaded fields.
Treat failures within fixed-size overloaded fields as malformed because those
fields are already fully present.

Ticket #8874

(cherry picked from commit e89b7644a8)
pull/16211/head
Giuseppe Longo 3 months ago committed by Jason Ish
parent 5b882dd0b3
commit dad8363d8a

@ -21,7 +21,7 @@ use crate::dhcp::dhcp::*;
use nom7::bytes::streaming::take;
use nom7::combinator::verify;
use nom7::number::streaming::{be_u16, be_u32, be_u8};
use nom7::IResult;
use nom7::{Err, IResult};
pub struct DHCPMessage {
pub header: DHCPHeader,
@ -233,10 +233,14 @@ pub fn parse_dhcp(input: &[u8]) -> IResult<&[u8], DHCPMessage> {
break;
}
}
Err(_) => {
Err(Err::Incomplete(_)) => {
truncated_options = true;
break;
}
Err(Err::Error(_)) | Err(Err::Failure(_)) => {
malformed_options = true;
break;
}
}
}
let message = DHCPMessage {

Loading…
Cancel
Save