@@ -26,22 +26,27 @@ private class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunctio
26
26
this .getParameter ( bufParam ) .getUnspecifiedType ( ) instanceof PointerType
27
27
}
28
28
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
+
29
34
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
30
35
// For these functions we add taint flow according to the following rules:
31
36
// 1. If the parameter is of a pointer type then there is taint from the
32
37
// indirection of the parameter. Otherwise, there is taint from the
33
38
// parameter.
34
39
// 2. If the return value is of a pointer type then there is taint to the
35
40
// 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
42
43
// Functions that end with _l also take a locale argument (always as the last argument),
43
44
// 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 )
45
50
) and
46
51
(
47
52
if this .getUnspecifiedType ( ) instanceof PointerType
@@ -59,8 +64,7 @@ private class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunctio
59
64
override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
60
65
exists ( int i |
61
66
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
64
68
// These functions always return the same pointer as they are given
65
69
this .hasGlobalOrStdOrBslName ( [ strrev ( ) , strlwr ( ) , strupr ( ) ] ) and
66
70
this .getParameter ( i ) .getUnspecifiedType ( ) instanceof PointerType and
0 commit comments