From: Philippe Antoine Date: Sun, 23 Jan 2022 20:30:22 +0000 (+0100) Subject: mqtt: parse properties with the right buffer's length X-Git-Tag: suricata-6.0.5~116 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18bf8c89d933e9ea320e7a397f4f0db11aa13ee3;p=thirdparty%2Fsuricata.git mqtt: parse properties with the right buffer's length (cherry picked from commit f0e869b26b6e913714db03b85039a0af38094419) --- diff --git a/rust/src/mqtt/parser.rs b/rust/src/mqtt/parser.rs index 86ad3d83b9..f936cf97ef 100644 --- a/rust/src/mqtt/parser.rs +++ b/rust/src/mqtt/parser.rs @@ -110,26 +110,24 @@ fn parse_properties(input: &[u8], precond: bool) -> IResult<&[u8], Option { + Ok((rem, proplen)) => { if proplen == 0 { // no properties return Ok((rem, None)); } // parse properties let mut props = Vec::::new(); - let mut newrem = rem; - while proplen > 0 { + let (rem, mut newrem) = take!(rem, proplen as usize)?; + while newrem.len() > 0 { match parse_property(newrem) { - Ok((rem, val)) => { + Ok((rem2, val)) => { props.push(val); - let curparselen = (newrem.len() - rem.len()) as u32; - proplen -= curparselen; - newrem = &rem; + newrem = rem2; } Err(e) => return Err(e), } } - return Ok((newrem, Some(props))); + return Ok((rem, Some(props))); } Err(e) => return Err(e), }