@@ -37,6 +37,25 @@ class UncalledFunction extends Function {
3737 }
3838}
3939
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+
4059predicate dataFlowOrTaintFlowFunction ( Function func , FunctionOutput output ) {
4160 func .( DataFlowFunction ) .hasDataFlow ( _, output ) or
4261 func .( TaintFunction ) .hasTaintFlow ( _, output )
@@ -132,13 +151,24 @@ predicate isSinkImpl(DataFlow::Node sink, Expr formatString) {
132151}
133152
134153module 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+ }
136161
137162 predicate isSink ( DataFlow:: Node sink ) { isSinkImpl ( sink , _) }
138163
139164 predicate isBarrier ( DataFlow:: Node node ) {
140165 // Ignore tracing non-const through array indices
141166 exists ( ArrayExpr a | a .getArrayOffset ( ) = node .asIndirectExpr ( ) )
167+ or
168+ exists ( Type t |
169+ t = node .getType ( ) and
170+ cannotContainString ( t )
171+ )
142172 }
143173}
144174
0 commit comments