@@ -37,6 +37,25 @@ class UncalledFunction extends Function {
37
37
}
38
38
}
39
39
40
+ /**
41
+ * Holds if `t` cannot refer to a string. That is, it's a built-in
42
+ * or arithmetic type that is not a "`char` like" type.
43
+ */
44
+ predicate cannotContainString ( Type t ) {
45
+ exists ( Type unspecified |
46
+ unspecified = t .getUnspecifiedType ( ) and
47
+ not unspecified instanceof UnknownType and
48
+ not unspecified instanceof CharType and
49
+ not unspecified instanceof WideCharType and
50
+ not unspecified instanceof Char8Type and
51
+ not unspecified instanceof Char16Type and
52
+ not unspecified instanceof Char32Type
53
+ |
54
+ unspecified instanceof ArithmeticType or
55
+ unspecified instanceof BuiltInType
56
+ )
57
+ }
58
+
40
59
predicate dataFlowOrTaintFlowFunction ( Function func , FunctionOutput output ) {
41
60
func .( DataFlowFunction ) .hasDataFlow ( _, output ) or
42
61
func .( TaintFunction ) .hasTaintFlow ( _, output )
@@ -132,13 +151,24 @@ predicate isSinkImpl(DataFlow::Node sink, Expr formatString) {
132
151
}
133
152
134
153
module NonConstFlowConfig implements DataFlow:: ConfigSig {
135
- predicate isSource ( DataFlow:: Node source ) { isNonConst ( source ) }
154
+ predicate isSource ( DataFlow:: Node source ) {
155
+ exists ( Type t |
156
+ isNonConst ( source ) and
157
+ t = source .getType ( ) and
158
+ not cannotContainString ( t )
159
+ )
160
+ }
136
161
137
162
predicate isSink ( DataFlow:: Node sink ) { isSinkImpl ( sink , _) }
138
163
139
164
predicate isBarrier ( DataFlow:: Node node ) {
140
165
// Ignore tracing non-const through array indices
141
166
exists ( ArrayExpr a | a .getArrayOffset ( ) = node .asIndirectExpr ( ) )
167
+ or
168
+ exists ( Type t |
169
+ t = node .getType ( ) and
170
+ cannotContainString ( t )
171
+ )
142
172
}
143
173
}
144
174
0 commit comments