@@ -7,7 +7,7 @@ import semmle.code.cpp.models.interfaces.Alias
77import semmle.code.cpp.models.interfaces.SideEffect
88
99/** The function `fopen` and friends. */
10- private class Fopen extends Function , AliasFunction , SideEffectFunction {
10+ private class Fopen extends Function , AliasFunction , SideEffectFunction , TaintFunction {
1111 Fopen ( ) {
1212 this .hasGlobalOrStdName ( [ "fopen" , "fopen_s" , "freopen" ] )
1313 or
@@ -47,4 +47,22 @@ private class Fopen extends Function, AliasFunction, SideEffectFunction {
4747 i = 0 and
4848 buffer = true
4949 }
50+
51+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
52+ (
53+ this .hasGlobalOrStdName ( [ "fopen" , "freopen" ] ) or
54+ this .hasGlobalName ( [ "_wfopen" , "_fsopen" , "_wfsopen" ] )
55+ ) and
56+ input .isParameterDeref ( 0 ) and
57+ output .isReturnValueDeref ( )
58+ or
59+ // The out parameter is a pointer to a `FILE*`.
60+ this .hasGlobalOrStdName ( "fopen_s" ) and
61+ input .isParameterDeref ( 1 ) and
62+ output .isParameterDeref ( 0 , 2 )
63+ or
64+ this .hasGlobalName ( [ "_open" , "_wopen" ] ) and
65+ input .isParameterDeref ( 0 ) and
66+ output .isReturnValue ( )
67+ }
5068}
0 commit comments