@@ -11,15 +11,14 @@ import semmle.code.cpp.models.interfaces.SideEffect
11
11
import semmle.code.cpp.models.interfaces.FlowSource
12
12
13
13
/**
14
- * The standard functions `gets ` and `fgets `.
14
+ * The standard functions `fgets ` and `fgetws `.
15
15
*/
16
- private class GetsFunction extends DataFlowFunction , TaintFunction , ArrayFunction , AliasFunction ,
16
+ private class FgetsFunction extends DataFlowFunction , TaintFunction , ArrayFunction , AliasFunction ,
17
17
SideEffectFunction , RemoteFlowSourceFunction {
18
- GetsFunction ( ) {
19
- // gets(str)
18
+ FgetsFunction ( ) {
20
19
// fgets(str, num, stream)
21
20
// fgetws(wstr, num, stream)
22
- this .hasGlobalOrStdOrBslName ( [ "gets" , " fgets", "fgetws" ] )
21
+ this .hasGlobalOrStdOrBslName ( [ "fgets" , "fgetws" ] )
23
22
}
24
23
25
24
override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
@@ -51,20 +50,61 @@ private class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunctio
51
50
override predicate hasRemoteFlowSource ( FunctionOutput output , string description ) {
52
51
output .isParameterDeref ( 0 ) and
53
52
description = "String read by " + this .getName ( )
53
+ or
54
+ output .isReturnValue ( ) and
55
+ description = "String read by " + this .getName ( )
54
56
}
55
57
56
58
override predicate hasArrayWithVariableSize ( int bufParam , int countParam ) {
57
- not this .hasName ( "gets" ) and
58
59
bufParam = 0 and
59
60
countParam = 1
60
61
}
61
62
62
- override predicate hasArrayWithUnknownSize ( int bufParam ) {
63
- this .hasName ( "gets" ) and
64
- bufParam = 0
63
+ override predicate hasArrayOutput ( int bufParam ) { bufParam = 0 }
64
+
65
+ override predicate hasSocketInput ( FunctionInput input ) { input .isParameterDeref ( 2 ) }
66
+ }
67
+
68
+ /**
69
+ * The standard functions `gets`.
70
+ */
71
+ private class GetsFunction extends DataFlowFunction , ArrayFunction , AliasFunction ,
72
+ SideEffectFunction , LocalFlowSourceFunction {
73
+ GetsFunction ( ) {
74
+ // gets(str)
75
+ this .hasGlobalOrStdOrBslName ( "gets" )
65
76
}
66
77
67
- override predicate hasArrayOutput ( int bufParam ) { bufParam = 0 }
78
+ override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
79
+ input .isParameter ( 0 ) and
80
+ output .isReturnValue ( )
81
+ }
82
+
83
+ override predicate parameterNeverEscapes ( int index ) { none ( ) }
84
+
85
+ override predicate parameterEscapesOnlyViaReturn ( int index ) { index = 0 }
68
86
69
- override predicate hasSocketInput ( FunctionInput input ) { input .isParameter ( 2 ) }
87
+ override predicate parameterIsAlwaysReturned ( int index ) { index = 0 }
88
+
89
+ override predicate hasOnlySpecificReadSideEffects ( ) { any ( ) }
90
+
91
+ override predicate hasOnlySpecificWriteSideEffects ( ) { any ( ) }
92
+
93
+ override predicate hasSpecificWriteSideEffect ( ParameterIndex i , boolean buffer , boolean mustWrite ) {
94
+ i = 0 and
95
+ buffer = true and
96
+ mustWrite = true
97
+ }
98
+
99
+ override predicate hasLocalFlowSource ( FunctionOutput output , string description ) {
100
+ output .isParameterDeref ( 0 ) and
101
+ description = "String read by " + this .getName ( )
102
+ or
103
+ output .isReturnValue ( ) and
104
+ description = "String read by " + this .getName ( )
105
+ }
106
+
107
+ override predicate hasArrayWithUnknownSize ( int bufParam ) { bufParam = 0 }
108
+
109
+ override predicate hasArrayOutput ( int bufParam ) { bufParam = 0 }
70
110
}
0 commit comments