Skip to content

Commit f8014fe

Browse files
committed
dhcp: distinguish malformed and truncated options
This patch distinguishes malformed DHCP options from truncated ones. Previously, the malformed_options field was never set, causing all option parsing failures to be reported as truncated. Ticket OISF#8874
1 parent 4a3528c commit f8014fe

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎rust/src/dhcp/parser.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::dhcp::dhcp::*;
2121
use nom8::bytes::streaming::take;
2222
use nom8::combinator::verify;
2323
use nom8::number::streaming::{be_u16, be_u32, be_u8};
24-
use nom8::{IResult, Parser};
24+
use nom8::{Err, IResult, Parser};
2525

2626
pub struct DHCPMessage {
2727
pub header: DHCPHeader,
@@ -242,7 +242,7 @@ pub fn parse_dhcp(input: &[u8]) -> IResult<&[u8], DHCPMessage> {
242242
Ok((rem, header)) => {
243243
let mut options = Vec::new();
244244
let mut next = rem;
245-
let malformed_options = false;
245+
let mut malformed_options = false;
246246
let mut truncated_options = false;
247247
loop {
248248
match parse_option(next) {
@@ -254,10 +254,14 @@ pub fn parse_dhcp(input: &[u8]) -> IResult<&[u8], DHCPMessage> {
254254
break;
255255
}
256256
}
257-
Err(_) => {
257+
Err(Err::Incomplete(_)) => {
258258
truncated_options = true;
259259
break;
260260
}
261+
Err(Err::Error(_)) | Err(Err::Failure(_)) => {
262+
malformed_options = true;
263+
break;
264+
}
261265
}
262266
}
263267
let overload = find_overload_value(&options);

0 commit comments

Comments
 (0)