]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mqtt: ensure we do not request extra data after buffering
authorJason Ish <jason.ish@oisf.net>
Tue, 19 Apr 2022 19:28:50 +0000 (13:28 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 19 Apr 2022 20:16:34 +0000 (22:16 +0200)
This is a minimal backport of 5618273ef4babc2fe8ff6a40848cd92dc4dfcdcf
to address ticket 5018.

Uses the "complete" version of take instead of the macro which is thre
streaming variant.

Ticket #5018

rust/src/mqtt/parser.rs

index f936cf97ef2405836dcfaa5e3e2e78d780d790e9..bd65d3c55929c695047290a074c89d525a9380e8 100644 (file)
@@ -22,6 +22,7 @@ use crate::mqtt::mqtt_property::*;
 use nom::combinator::rest;
 use nom::number::streaming::*;
 use nom::*;
+use nom::multi::length_data;
 use num_traits::FromPrimitive;
 
 #[derive(Debug)]
@@ -54,14 +55,11 @@ fn convert_varint(continued: Vec<u8>, last: u8) -> u32 {
 
 // DATA TYPES
 
-named!(#[inline], pub parse_mqtt_string<String>,
-       do_parse!(
-           length: be_u16
-           >> content: take!(length)
-           >>  (
-                 String::from_utf8_lossy(&content).to_string()
-               )
-       ));
+#[inline]
+pub fn parse_mqtt_string(i: &[u8]) -> IResult<&[u8], String> {
+    let (i, content) = length_data(be_u16)(i)?;
+    Ok((i, String::from_utf8_lossy(content).to_string()))
+}
 
 named!(#[inline], pub parse_mqtt_variable_integer<u32>,
        do_parse!(
@@ -117,7 +115,7 @@ fn parse_properties(input: &[u8], precond: bool) -> IResult<&[u8], Option<Vec<MQ
             }
             // parse properties
             let mut props = Vec::<MQTTProperty>::new();
-            let (rem, mut newrem) = take!(rem, proplen as usize)?;
+            let (rem, mut newrem) = nom::bytes::complete::take(proplen as usize)(rem)?;
             while newrem.len() > 0 {
                 match parse_property(newrem) {
                     Ok((rem2, val)) => {