Skip to content

Commit bcc6312

Browse files
committed
Fix bug in yr_re_fast_exec causing assertion in _yr_scan_match_callback
When an arbitrary file is scanned with the rule below it triggers the assertion at https://github.com/VirusTotal/yara/blob/v4.3.1/libyara/scan.c#L670 ``` rule test { strings: $a = { 31[-][8-][-]30 } condition: $a } ```
1 parent 2653732 commit bcc6312

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

libyara/re.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2291,10 +2291,11 @@ int yr_re_fast_exec(
22912291
break;
22922292

22932293
case RE_OPCODE_REPEAT_ANY_UNGREEDY:
2294-
if (bytes_matched >= max_bytes_matched)
2294+
repeat_any_args = (RE_REPEAT_ANY_ARGS*) (ip + 1);
2295+
2296+
if (bytes_matched + repeat_any_args->min >= max_bytes_matched)
22952297
break;
22962298

2297-
repeat_any_args = (RE_REPEAT_ANY_ARGS*) (ip + 1);
22982299
match = true;
22992300

23002301
const uint8_t* next_opcode = ip + 1 + sizeof(RE_REPEAT_ANY_ARGS);

tests/test-rules.c

+12
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,18 @@ static void test_hex_strings()
16011601
condition: $a }",
16021602
"123440004");
16031603

1604+
assert_true_rule(
1605+
"rule test { \
1606+
strings: $a = { 31[-][8-][-]30 } \
1607+
condition: $a }",
1608+
"1234567890");
1609+
1610+
assert_false_rule(
1611+
"rule test { \
1612+
strings: $a = { 31[-][9-][-]30 } \
1613+
condition: $a }",
1614+
"1234567890");
1615+
16041616
assert_error(
16051617
"rule test { \
16061618
strings: $a = { 01 [0] 02 } \

0 commit comments

Comments
 (0)