Skip to content

Commit c80cd9d

Browse files
committed
Fix issue with matches operator not matching empty strings
The `matches` operator was returning false if the left operand was an empty strings. So, `"" matches <some regexp>` was returning false regardless of the regexp used. However, some regexp *do* match the empty strings, like for example `/foo|/`.
1 parent 8748502 commit c80cd9d

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

libyara/exec.c

-7
Original file line numberDiff line numberDiff line change
@@ -1967,13 +1967,6 @@ int yr_execute_code(YR_SCAN_CONTEXT* context)
19671967
ensure_defined(r2);
19681968
ensure_defined(r1);
19691969

1970-
if (r1.ss->length == 0)
1971-
{
1972-
r1.i = false;
1973-
push(r1);
1974-
break;
1975-
}
1976-
19771970
result = yr_re_exec(
19781971
context,
19791972
(uint8_t*) r2.re->code,

tests/test-rules.c

+4
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,10 @@ static void test_matches_operator()
29532953
assert_false_rule(
29542954
"rule test { condition: \"foo\\nbar\" matches /foo.*bar/ }", NULL);
29552955

2956+
assert_true_rule("rule test { condition: \"\" matches /foo|/ }", NULL);
2957+
2958+
assert_true_rule("rule test { condition: \"\" matches /a||b/ }", NULL);
2959+
29562960
YR_DEBUG_FPRINTF(1, stderr, "} // %s()\n", __FUNCTION__);
29572961
}
29582962

0 commit comments

Comments
 (0)