@@ -11,15 +11,14 @@ import semmle.code.cpp.models.interfaces.SideEffect
1111import semmle.code.cpp.models.interfaces.FlowSource
1212
1313/**
14- * The standard functions `gets ` and `fgets `.
14+ * The standard functions `fgets ` and `fgetws `.
1515 */
16- private class GetsFunction extends DataFlowFunction , TaintFunction , ArrayFunction , AliasFunction ,
16+ private class FgetsFunction extends DataFlowFunction , TaintFunction , ArrayFunction , AliasFunction ,
1717 SideEffectFunction , RemoteFlowSourceFunction {
18- GetsFunction ( ) {
19- // gets(str)
18+ FgetsFunction ( ) {
2019 // fgets(str, num, stream)
2120 // fgetws(wstr, num, stream)
22- this .hasGlobalOrStdOrBslName ( [ "gets" , " fgets", "fgetws" ] )
21+ this .hasGlobalOrStdOrBslName ( [ "fgets" , "fgetws" ] )
2322 }
2423
2524 override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
@@ -51,20 +50,61 @@ private class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunctio
5150 override predicate hasRemoteFlowSource ( FunctionOutput output , string description ) {
5251 output .isParameterDeref ( 0 ) and
5352 description = "String read by " + this .getName ( )
53+ or
54+ output .isReturnValue ( ) and
55+ description = "String read by " + this .getName ( )
5456 }
5557
5658 override predicate hasArrayWithVariableSize ( int bufParam , int countParam ) {
57- not this .hasName ( "gets" ) and
5859 bufParam = 0 and
5960 countParam = 1
6061 }
6162
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" )
6576 }
6677
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 }
6886
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 }
70110}
0 commit comments