From 7dfddab9ede45baf17263d491b618c05d5cd96b4 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 27 Jun 2024 13:42:34 +0200 Subject: [PATCH] detect: parse units for integer for every cases Ticket: #6423 Not just equality, but also >3MB should work For example flow.bytes_toserver>3MB --- rust/src/detect/uint.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/src/detect/uint.rs b/rust/src/detect/uint.rs index fdfc4c30f89f..23438a2759df 100644 --- a/rust/src/detect/uint.rs +++ b/rust/src/detect/uint.rs @@ -113,13 +113,13 @@ pub fn detect_parse_uint_value_hex(i: &str) -> IResult<&str, T pub fn detect_parse_uint_value(i: &str) -> IResult<&str, T> { let (i, arg1) = alt(( detect_parse_uint_value_hex, - map_opt(digit1, |s: &str| s.parse::().ok()), + detect_parse_uint_with_unit, ))(i)?; Ok((i, arg1)) } pub fn detect_parse_uint_with_unit(i: &str) -> IResult<&str, T> { - let (i, arg1) = detect_parse_uint_value::(i)?; + let (i, arg1) = map_opt(digit1, |s: &str| s.parse::().ok())(i)?; let (i, unit) = opt(detect_parse_uint_unit)(i)?; if arg1 >= T::one() { if let Some(u) = unit { @@ -138,7 +138,7 @@ pub fn detect_parse_uint_start_equal( ) -> IResult<&str, DetectUintData> { let (i, _) = opt(tag("="))(i)?; let (i, _) = opt(is_a(" "))(i)?; - let (i, arg1) = detect_parse_uint_with_unit(i)?; + let (i, arg1) = detect_parse_uint_value(i)?; Ok(( i, DetectUintData { @@ -578,7 +578,7 @@ mod tests { assert!(detect_parse_uint::("2kb").is_err()); - let (_, val) = detect_parse_uint::("3MB").unwrap(); + let (_, val) = detect_parse_uint::("> 3MB").unwrap(); assert_eq!(val.arg1, 3 * 1024 * 1024); } }