|
18 | 18 | use nom7::branch::alt; |
19 | 19 | use nom7::bytes::complete::{is_a, tag, tag_no_case, take, take_while}; |
20 | 20 | use nom7::character::complete::{anychar, char, digit1, hex_digit1, i32 as nom_i32}; |
21 | | -use nom7::combinator::{all_consuming, map_opt, opt, value, verify}; |
| 21 | +use nom7::combinator::{all_consuming, cut, map_opt, opt, value, verify}; |
22 | 22 | use nom7::error::{make_error, Error, ErrorKind}; |
23 | 23 | use nom7::Err; |
24 | 24 | use nom7::IResult; |
@@ -585,9 +585,13 @@ pub fn detect_parse_uint_start_interval<T: DetectIntType>( |
585 | 585 | let (i, _) = opt(is_a(" "))(i)?; |
586 | 586 | let (i, _) = alt((tag("-"), tag("<>")))(i)?; |
587 | 587 | let (i, _) = opt(is_a(" "))(i)?; |
588 | | - let (i, arg2) = verify(detect_parse_uint_value, |x| { |
| 588 | + |
| 589 | + // As we've determined this is range, use cut to turn the error |
| 590 | + // into a failure so usage inside alt doesn't continue onto the |
| 591 | + // next item. |
| 592 | + let (i, arg2) = cut(verify(detect_parse_uint_value, |x| { |
589 | 593 | x > &arg1 && *x - arg1 > T::one() |
590 | | - })(i)?; |
| 594 | + }))(i)?; |
591 | 595 | let mode = if neg.is_some() { |
592 | 596 | DetectUintMode::DetectUintModeNegRg |
593 | 597 | } else { |
@@ -1043,4 +1047,13 @@ mod tests { |
1043 | 1047 | assert!(detect_parse_uint::<u8>("").is_err()); |
1044 | 1048 | assert!(detect_parse_uint::<u8>("<444").is_err()); |
1045 | 1049 | } |
| 1050 | + |
| 1051 | + #[test] |
| 1052 | + fn test_invalid_range() { |
| 1053 | + // Invalid range - should fail (not enough values between bounds) |
| 1054 | + assert!(detect_parse_uint_notending::<u8>("1<>2").is_err()); |
| 1055 | + assert!(detect_parse_uint_notending::<u8>("1-2").is_err()); |
| 1056 | + assert!(detect_parse_uint_notending::<u8>("1-1").is_err()); |
| 1057 | + assert!(detect_parse_uint_notending::<u8>("1-foo").is_err()); |
| 1058 | + } |
1046 | 1059 | } |
0 commit comments