File tree 2 files changed +45
-24
lines changed
2 files changed +45
-24
lines changed Original file line number Diff line number Diff line change @@ -1610,11 +1610,20 @@ int yr_execute_code(YR_SCAN_CONTEXT* context)
1610
1610
1611
1611
pop (r2 ); // Offset range end
1612
1612
pop (r1 ); // Offset range start
1613
+ pop (r3 ); // First string
1613
1614
1614
- ensure_defined (r1 );
1615
- ensure_defined (r2 );
1616
-
1617
- pop (r3 );
1615
+ // If any of the range boundaries are undefined the result is also
1616
+ // undefined, be we need to unwind the stack first.
1617
+ if (is_undef (r1 ) || is_undef (r2 ))
1618
+ {
1619
+ // Remove all the strings.
1620
+ while (!is_undef (r3 )) pop (r3 );
1621
+ // Remove the quantifier at the bottom of the stack.
1622
+ pop (r3 );
1623
+ r1 .i = YR_UNDEFINED ;
1624
+ push (r1 );
1625
+ break ;
1626
+ }
1618
1627
1619
1628
while (!is_undef (r3 ))
1620
1629
{
Original file line number Diff line number Diff line change @@ -1947,6 +1947,38 @@ static void test_of()
1947
1947
}" ,
1948
1948
"mississippi" );
1949
1949
1950
+ // If one of the bounds can not be determined statically it isn't an error.
1951
+ assert_true_rule (
1952
+ "rule test { \
1953
+ strings: \
1954
+ $a = \"AXSERS\" \
1955
+ condition: \
1956
+ true or any of them in (0..filesize-100) \
1957
+ }" ,
1958
+ TEXT_1024_BYTES );
1959
+
1960
+ // Lower bound can not be negative, if it can be determined statically.
1961
+ assert_error (
1962
+ "rule test { \
1963
+ strings: \
1964
+ $a = \"AXSERS\" \
1965
+ condition: \
1966
+ $a in (-1..10) \
1967
+ }" ,
1968
+ ERROR_INVALID_VALUE );
1969
+
1970
+ // Make sure that an undefined range boundary returns an undefined value,
1971
+ // which translates to false.
1972
+ assert_false_rule (
1973
+ "import \"tests\" \
1974
+ rule test { \
1975
+ strings: \
1976
+ $a = \"missi\" \
1977
+ condition: \
1978
+ any of them in (0..tests.undefined.i) \
1979
+ }" ,
1980
+ "mississippi" );
1981
+
1950
1982
YR_DEBUG_FPRINTF (1 , stderr , "} // %s()\n" , __FUNCTION__ );
1951
1983
}
1952
1984
@@ -2184,26 +2216,6 @@ void test_for()
2184
2216
}" ,
2185
2217
ERROR_INVALID_VALUE );
2186
2218
2187
- // If one of the bounds can not be determined statically it isn't an error.
2188
- assert_true_rule (
2189
- "rule test { \
2190
- strings: \
2191
- $a = \"AXSERS\" \
2192
- condition: \
2193
- true or any of them in (0..filesize-100) \
2194
- }" ,
2195
- TEXT_1024_BYTES );
2196
-
2197
- // Lower bound can not be negative, if it can be determined statically.
2198
- assert_error (
2199
- "rule test { \
2200
- strings: \
2201
- $a = \"AXSERS\" \
2202
- condition: \
2203
- $a in (-1..10) \
2204
- }" ,
2205
- ERROR_INVALID_VALUE );
2206
-
2207
2219
// Test case for https://github.com/VirusTotal/yara/issues/1729
2208
2220
assert_true_rule (
2209
2221
"rule test { \
You can’t perform that action at this time.
0 commit comments