File tree 2 files changed +24
-6
lines changed
2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -1049,10 +1049,12 @@ int yr_execute_code(YR_SCAN_CONTEXT* context)
1049
1049
pop (r1 );
1050
1050
ensure_defined (r2 );
1051
1051
ensure_defined (r1 );
1052
- if ( r2 . i != 0 )
1053
- r1 . i = r1 . i % r2 . i ;
1054
- else
1052
+ // If divisor is zero the result is undefined. It's also undefined
1053
+ // when dividing INT64_MIN by -1.
1054
+ if ( r2 . i == 0 || ( r1 . i == INT64_MIN && r2 . i == -1 ))
1055
1055
r1 .i = YR_UNDEFINED ;
1056
+ else
1057
+ r1 .i = r1 .i % r2 .i ;
1056
1058
push (r1 );
1057
1059
break ;
1058
1060
@@ -2099,10 +2101,12 @@ int yr_execute_code(YR_SCAN_CONTEXT* context)
2099
2101
pop (r1 );
2100
2102
ensure_defined (r2 );
2101
2103
ensure_defined (r1 );
2102
- if ( r2 . i != 0 )
2103
- r1 . i = r1 . i / r2 . i ;
2104
- else
2104
+ // If divisor is zero the result is undefined. It's also undefined
2105
+ // when dividing INT64_MIN by -1.
2106
+ if ( r2 . i == 0 || ( r1 . i == INT64_MIN && r2 . i == -1 ))
2105
2107
r1 .i = YR_UNDEFINED ;
2108
+ else
2109
+ r1 .i = r1 .i / r2 .i ;
2106
2110
push (r1 );
2107
2111
break ;
2108
2112
Original file line number Diff line number Diff line change @@ -3727,6 +3727,20 @@ void test_defined()
3727
3727
not defined ($a at pe.number_of_resources) \
3728
3728
}" ,
3729
3729
NULL );
3730
+
3731
+ // Test that operations that would trigger a SIGFPE are detected and
3732
+ // returns undefined
3733
+ assert_true_rule (
3734
+ "rule t { \
3735
+ strings: \
3736
+ $a = /aaa/ \
3737
+ condition: \
3738
+ (not defined (1 \\ #a)) and \
3739
+ (not defined (1 % #a)) and \
3740
+ (not defined ((#a + -0x7FFFFFFFFFFFFFFF - 1) \\ -1)) and \
3741
+ (not defined ((#a + -0x7FFFFFFFFFFFFFFF - 1) % -1)) \
3742
+ }" ,
3743
+ NULL );
3730
3744
}
3731
3745
3732
3746
static void test_pass (int pass )
You can’t perform that action at this time.
0 commit comments