@@ -26,22 +26,27 @@ private class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunctio
2626 this .getParameter ( bufParam ) .getUnspecifiedType ( ) instanceof PointerType
2727 }
2828
29+ /** Holds if `i` is a locale parameter that does not carry taint. */
30+ private predicate isLocaleParameter ( ParameterIndex i ) {
31+ this .getName ( ) .matches ( "%\\_l" ) and i + 1 = this .getNumberOfParameters ( )
32+ }
33+
2934 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
3035 // For these functions we add taint flow according to the following rules:
3136 // 1. If the parameter is of a pointer type then there is taint from the
3237 // indirection of the parameter. Otherwise, there is taint from the
3338 // parameter.
3439 // 2. If the return value is of a pointer type then there is taint to the
3540 // indirection of the return. Otherwise, there is taint to the return.
36- exists ( ParameterIndex i | exists ( this .getParameter ( i ) ) |
37- (
38- if this .getParameter ( i ) .getUnspecifiedType ( ) instanceof PointerType
39- then input .isParameterDeref ( i )
40- else input .isParameter ( i )
41- ) and
41+ exists ( ParameterIndex i |
42+ exists ( this .getParameter ( i ) ) and
4243 // Functions that end with _l also take a locale argument (always as the last argument),
4344 // and we don't want taint from those arguments.
44- ( not this .getName ( ) .matches ( "%\\_l" ) or exists ( this .getParameter ( i + 1 ) ) )
45+ not this .isLocaleParameter ( i )
46+ |
47+ if this .getParameter ( i ) .getUnspecifiedType ( ) instanceof PointerType
48+ then input .isParameterDeref ( i )
49+ else input .isParameter ( i )
4550 ) and
4651 (
4752 if this .getUnspecifiedType ( ) instanceof PointerType
@@ -59,8 +64,7 @@ private class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunctio
5964 override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
6065 exists ( int i |
6166 input .isParameter ( i ) and
62- // see the comment in `hasTaintFlow` for an explanation
63- ( not this .getName ( ) .matches ( "%\\_l" ) or exists ( this .getParameter ( i + 1 ) ) ) and
67+ not this .isLocaleParameter ( i ) and
6468 // These functions always return the same pointer as they are given
6569 this .hasGlobalOrStdOrBslName ( [ strrev ( ) , strlwr ( ) , strupr ( ) ] ) and
6670 this .getParameter ( i ) .getUnspecifiedType ( ) instanceof PointerType and
0 commit comments