@@ -19,6 +19,58 @@ import semmle.code.cpp.security.TaintTracking
19
19
import TaintedWithPath
20
20
import Bounded
21
21
22
+ /**
23
+ * A function that outputs random data such as `std::rand`.
24
+ */
25
+ abstract class RandomFunction extends Function {
26
+ /**
27
+ * Gets the `FunctionOutput` that describes how this function returns the random data.
28
+ */
29
+ FunctionOutput getFunctionOutput ( ) { result .isReturnValue ( ) }
30
+ }
31
+
32
+ /**
33
+ * The standard function `std::rand`.
34
+ */
35
+ private class StdRand extends RandomFunction {
36
+ StdRand ( ) {
37
+ this .hasGlobalOrStdOrBslName ( "rand" ) and
38
+ this .getNumberOfParameters ( ) = 0
39
+ }
40
+ }
41
+
42
+ /**
43
+ * The Unix function `rand_r`.
44
+ */
45
+ private class RandR extends RandomFunction {
46
+ RandR ( ) {
47
+ this .hasGlobalName ( "rand_r" ) and
48
+ this .getNumberOfParameters ( ) = 1
49
+ }
50
+ }
51
+
52
+ /**
53
+ * The Unix function `random`.
54
+ */
55
+ private class Random extends RandomFunction {
56
+ Random ( ) {
57
+ this .hasGlobalName ( "random" ) and
58
+ this .getNumberOfParameters ( ) = 1
59
+ }
60
+ }
61
+
62
+ /**
63
+ * The Windows `rand_s` function.
64
+ */
65
+ private class RandS extends RandomFunction {
66
+ RandS ( ) {
67
+ this .hasGlobalName ( "rand_s" ) and
68
+ this .getNumberOfParameters ( ) = 1
69
+ }
70
+
71
+ override FunctionOutput getFunctionOutput ( ) { result .isParameterDeref ( 0 ) }
72
+ }
73
+
22
74
predicate isUnboundedRandCall ( FunctionCall fc ) {
23
75
exists ( Function func | func = fc .getTarget ( ) |
24
76
func .hasGlobalOrStdOrBslName ( "rand" ) and
0 commit comments