]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: parse units for integer for every cases
authorPhilippe Antoine <pantoine@oisf.net>
Thu, 27 Jun 2024 11:42:34 +0000 (13:42 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 3 Jul 2024 05:55:37 +0000 (07:55 +0200)
Ticket: #6423

Not just equality, but also >3MB should work
For example flow.bytes_toserver>3MB

rust/src/detect/uint.rs

index fdfc4c30f89fa4390fc2d40e61a4091853af724a..23438a2759df5cb1a1ae67b7a3e5be441dbecc08 100644 (file)
@@ -113,13 +113,13 @@ pub fn detect_parse_uint_value_hex<T: DetectIntType>(i: &str) -> IResult<&str, T
 pub fn detect_parse_uint_value<T: DetectIntType>(i: &str) -> IResult<&str, T> {
     let (i, arg1) = alt((
         detect_parse_uint_value_hex,
-        map_opt(digit1, |s: &str| s.parse::<T>().ok()),
+        detect_parse_uint_with_unit,
     ))(i)?;
     Ok((i, arg1))
 }
 
 pub fn detect_parse_uint_with_unit<T: DetectIntType>(i: &str) -> IResult<&str, T> {
-    let (i, arg1) = detect_parse_uint_value::<T>(i)?;
+    let (i, arg1) = map_opt(digit1, |s: &str| s.parse::<T>().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<T: DetectIntType>(
 ) -> IResult<&str, DetectUintData<T>> {
     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::<u8>("2kb").is_err());
 
-        let (_, val) = detect_parse_uint::<u32>("3MB").unwrap();
+        let (_, val) = detect_parse_uint::<u32>("3MB").unwrap();
         assert_eq!(val.arg1, 3 * 1024 * 1024);
     }
 }