]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mqtt: parse properties with the right buffer's length
authorPhilippe Antoine <contact@catenacyber.fr>
Sun, 23 Jan 2022 20:30:22 +0000 (21:30 +0100)
committerShivani Bhardwaj <shivanib134@gmail.com>
Fri, 4 Mar 2022 05:38:17 +0000 (11:08 +0530)
(cherry picked from commit f0e869b26b6e913714db03b85039a0af38094419)

rust/src/mqtt/parser.rs

index 86ad3d83b9ed680f30d100dcbb23c8dc6a0a5bf7..f936cf97ef2405836dcfaa5e3e2e78d780d790e9 100644 (file)
@@ -110,26 +110,24 @@ fn parse_properties(input: &[u8], precond: bool) -> IResult<&[u8], Option<Vec<MQ
     }
     // parse properties length
     match parse_mqtt_variable_integer(input) {
-        Ok((rem, mut proplen)) => {
+        Ok((rem, proplen)) => {
             if proplen == 0 {
                 // no properties
                 return Ok((rem, None));
             }
             // parse properties
             let mut props = Vec::<MQTTProperty>::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),
     }