@@ -51,6 +51,15 @@ predicate underscoreMacro(Expr e) {
51
51
)
52
52
}
53
53
54
+ /**
55
+ * Holds if `t` cannot hold a character array, directly or indirectly.
56
+ */
57
+ predicate cannotContainString ( Type t ) {
58
+ t .getUnspecifiedType ( ) instanceof BuiltInType
59
+ or
60
+ t .getUnspecifiedType ( ) instanceof IntegralOrEnumType
61
+ }
62
+
54
63
predicate isNonConst ( DataFlow:: Node node ) {
55
64
exists ( Expr e | e = node .asExpr ( ) |
56
65
exists ( FunctionCall fc | fc = e .( FunctionCall ) |
@@ -99,16 +108,26 @@ predicate isNonConst(DataFlow::Node node) {
99
108
node instanceof DataFlow:: DefinitionByReferenceNode
100
109
}
101
110
111
+ pragma [ noinline]
112
+ predicate isSanitizerNode ( DataFlow:: Node node ) {
113
+ underscoreMacro ( node .asExpr ( ) )
114
+ or
115
+ cannotContainString ( node .getType ( ) )
116
+ }
117
+
102
118
class NonConstFlow extends TaintTracking:: Configuration {
103
119
NonConstFlow ( ) { this = "NonConstFlow" }
104
120
105
- override predicate isSource ( DataFlow:: Node source ) { isNonConst ( source ) }
121
+ override predicate isSource ( DataFlow:: Node source ) {
122
+ isNonConst ( source ) and
123
+ not cannotContainString ( source .getType ( ) )
124
+ }
106
125
107
126
override predicate isSink ( DataFlow:: Node sink ) {
108
127
exists ( FormattingFunctionCall fc | sink .asExpr ( ) = fc .getArgument ( fc .getFormatParameterIndex ( ) ) )
109
128
}
110
129
111
- override predicate isSanitizer ( DataFlow:: Node node ) { underscoreMacro ( node . asExpr ( ) ) }
130
+ override predicate isSanitizer ( DataFlow:: Node node ) { isSanitizerNode ( node ) }
112
131
}
113
132
114
133
from FormattingFunctionCall call , Expr formatString
0 commit comments