@@ -42,8 +42,16 @@ predicate whitelistFunction(Function f, int arg) {
4242 ( arg = 1 or arg = 2 )
4343}
4444
45+ < < < < < < < HEAD
4546predicate whitelisted( FunctionCall fc ) {
4647 exists ( Function f , int arg | f = fc .getTarget ( ) | whitelistFunction ( f , arg ) )
48+ = = = = = = =
49+ predicate underscoreMacro( Expr e ) {
50+ exists ( MacroInvocation mi |
51+ mi .getMacroName ( ) = "_" and
52+ mi .getExpr ( ) = e
53+ )
54+ > > > > > > > [ CPP - 370 ] First attempt at isAdditionalFlowStep ( ) .
4755}
4856
4957predicate isNonConst ( DataFlow:: Node node) {
@@ -88,11 +96,26 @@ predicate isNonConst(DataFlow::Node node) {
8896 )
8997 )
9098 or
99+ < < < < < < < HEAD
91100 node instanceof DataFlow:: DefinitionByReferenceNode
92101}
93102
94103class NonConstFlow extends TaintTracking:: Configuration {
95104 NonConstFlow ( ) { this = "NonConstFlow" }
105+ = = = = = = =
106+ // we let the '_' macro through regardless of what it points at
107+ underscoreMacro ( e )
108+ }
109+
110+ predicate isConst( Expr e) {
111+ e instanceof StringLiteral
112+ or
113+ whitelisted ( e )
114+ }
115+
116+ class ConstFlow extends DataFlow:: Configuration {
117+ ConstFlow ( ) { this = "ConstFlow" }
118+ > > > > > > > [ CPP - 370 ] First attempt at isAdditionalFlowStep ( ) .
96119
97120 override predicate isSource ( DataFlow:: Node source ) { isNonConst ( source ) }
98121
@@ -101,6 +124,20 @@ class NonConstFlow extends TaintTracking::Configuration {
101124 sink .asExpr ( ) = fc .getArgument ( fc .getFormatParameterIndex ( ) )
102125 )
103126 }
127+
128+ override predicate isAdditionalFlowStep ( DataFlow:: Node source , DataFlow:: Node sink ) {
129+ none ( )
130+ or
131+ // an element picked from an array of string literals is a string literal
132+ exists ( Variable v , int a |
133+ a = sink .asExpr ( ) .( ArrayExpr ) .getArrayOffset ( ) .getValue ( ) .toInt ( ) and
134+ v = sink .asExpr ( ) .( ArrayExpr ) .getArrayBase ( ) .( VariableAccess ) .getTarget ( )
135+ |
136+ // we disallow parameters, since they may be bound to unsafe arguments
137+ // at various call sites.
138+ not v instanceof Parameter and source .asExpr ( ) instanceof StringLiteral
139+ )
140+ }
104141}
105142
106143from FormattingFunctionCall call , Expr formatString
0 commit comments