File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
test/query-tests/Security/CWE/CWE-190/semmle/uncontrolled Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,11 @@ import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
19
19
import TaintedWithPath
20
20
21
21
predicate isUnboundedRandCall ( FunctionCall fc ) {
22
- fc .getTarget ( ) .getName ( ) = "rand" and not bounded ( fc )
22
+ exists ( Function func | func = fc .getTarget ( ) |
23
+ func .hasGlobalOrStdOrBslName ( "rand" ) and
24
+ not bounded ( fc ) and
25
+ func .getNumberOfParameters ( ) = 0
26
+ )
23
27
}
24
28
25
29
/**
@@ -84,6 +88,10 @@ predicate bounded(Expr e) {
84
88
boundedDiv ( e , any ( DivExpr div ) .getLeftOperand ( ) )
85
89
or
86
90
boundedDiv ( e , any ( AssignDivExpr div ) .getLValue ( ) )
91
+ or
92
+ boundedDiv ( e , any ( RShiftExpr shift ) .getLeftOperand ( ) )
93
+ or
94
+ boundedDiv ( e , any ( AssignRShiftExpr div ) .getLValue ( ) )
87
95
}
88
96
89
97
predicate isUnboundedRandCallOrParent ( Expr e ) {
Original file line number Diff line number Diff line change @@ -37,3 +37,14 @@ void randomTester2()
37
37
r = r + 100 ; // BAD
38
38
}
39
39
}
40
+
41
+ int rand (int min, int max);
42
+ unsigned rand (int max);
43
+
44
+ void test_with_bounded_randomness () {
45
+ int r = rand (0 , 10 );
46
+ r++; // GOOD
47
+
48
+ unsigned unsigned_r = rand (10 );
49
+ unsigned_r++; // GOOD
50
+ }
You can’t perform that action at this time.
0 commit comments