@@ -108,106 +108,136 @@ private FunctionInput getIteratorArgumentInput(Operator op, int index) {
108
108
}
109
109
110
110
/**
111
- * A non-member prefix `operator* ` function for an iterator type.
111
+ * A non-member `operator++` or `operator-- ` function for an iterator type.
112
112
*/
113
- private class IteratorPointerDereferenceOperator extends Operator , TaintFunction ,
114
- IteratorReferenceFunction {
115
- FunctionInput iteratorInput ;
116
-
117
- IteratorPointerDereferenceOperator ( ) {
118
- this .hasName ( "operator*" ) and
119
- iteratorInput = getIteratorArgumentInput ( this , 0 )
113
+ class IteratorCrementNonMemberOperator extends Operator {
114
+ IteratorCrementNonMemberOperator ( ) {
115
+ this .hasName ( [ "operator++" , "operator--" ] ) and
116
+ exists ( getIteratorArgumentInput ( this , 0 ) )
120
117
}
118
+ }
121
119
122
- override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
123
- input = iteratorInput and
120
+ private class IteratorCrementNonMemberOperatorModel extends IteratorCrementNonMemberOperator ,
121
+ DataFlowFunction {
122
+ override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
123
+ input = getIteratorArgumentInput ( this , 0 ) and
124
124
output .isReturnValue ( )
125
125
or
126
- input .isReturnValueDeref ( ) and
127
- output .isParameterDeref ( 0 )
126
+ input .isParameterDeref ( 0 ) and output .isReturnValueDeref ( )
128
127
}
129
128
}
130
129
131
130
/**
132
- * A non-member `operator++` or `operator--` function for an iterator type.
131
+ * An `operator++` or `operator--` member function for an iterator type.
133
132
*/
134
- class IteratorCrementOperator extends Operator {
135
- FunctionInput iteratorInput ;
136
-
137
- IteratorCrementOperator ( ) {
138
- this .hasName ( [ "operator++" , "operator--" ] ) and
139
- iteratorInput = getIteratorArgumentInput ( this , 0 )
133
+ class IteratorCrementMemberOperator extends MemberFunction {
134
+ IteratorCrementMemberOperator ( ) {
135
+ this .getClassAndName ( [ "operator++" , "operator--" ] ) instanceof Iterator
140
136
}
141
-
142
- /**
143
- * INTERNAL: Do not use.
144
- */
145
- FunctionInput getIteratorInput ( ) { result = iteratorInput }
146
137
}
147
138
148
- private class IteratorCrementOperatorModel extends IteratorCrementOperator , DataFlowFunction {
139
+ private class IteratorCrementMemberOperatorModel extends IteratorCrementMemberOperator ,
140
+ DataFlowFunction , TaintFunction {
149
141
override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
150
- input = this . getIteratorInput ( ) and
142
+ input . isQualifierAddress ( ) and
151
143
output .isReturnValue ( )
152
144
or
153
- input .isParameterDeref ( 0 ) and output .isReturnValueDeref ( )
145
+ input .isReturnValueDeref ( ) and
146
+ output .isQualifierObject ( )
147
+ or
148
+ input .isQualifierObject ( ) and
149
+ output .isReturnValueDeref ( )
150
+ }
151
+
152
+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
153
+ input .isQualifierObject ( ) and
154
+ output .isReturnValueDeref ( )
154
155
}
155
156
}
156
157
157
158
/**
158
- * A non-member `operator+` function for an iterator type.
159
+ * A (member or non-member) `operator++` or `operator-- ` function for an iterator type.
159
160
*/
160
- class IteratorAddOperator extends Operator {
161
- FunctionInput iteratorInput ;
161
+ class IteratorCrementOperator extends Function {
162
+ IteratorCrementOperator ( ) {
163
+ this instanceof IteratorCrementNonMemberOperator or
164
+ this instanceof IteratorCrementMemberOperator
165
+ }
166
+ }
162
167
163
- IteratorAddOperator ( ) {
168
+ /**
169
+ * A non-member `operator+` function for an iterator type.
170
+ */
171
+ class IteratorAddNonMemberOperator extends Operator {
172
+ IteratorAddNonMemberOperator ( ) {
164
173
this .hasName ( "operator+" ) and
165
- iteratorInput = getIteratorArgumentInput ( this , [ 0 , 1 ] )
174
+ exists ( getIteratorArgumentInput ( this , [ 0 , 1 ] ) )
175
+ }
176
+ }
177
+
178
+ private class IteratorAddNonMemberOperatorModel extends IteratorAddNonMemberOperator , TaintFunction {
179
+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
180
+ input = getIteratorArgumentInput ( this , [ 0 , 1 ] ) and
181
+ output .isReturnValue ( )
166
182
}
183
+ }
167
184
168
- FunctionInput getIteratorInput ( ) { result = iteratorInput }
185
+ /**
186
+ * An `operator+` or `operator-` member function of an iterator class.
187
+ */
188
+ class IteratorBinaryArithmeticMemberOperator extends MemberFunction {
189
+ IteratorBinaryArithmeticMemberOperator ( ) {
190
+ this .getClassAndName ( [ "operator+" , "operator-" ] ) instanceof Iterator
191
+ }
169
192
}
170
193
171
- private class IteratorAddOperatorModel extends IteratorAddOperator , TaintFunction {
194
+ private class IteratorBinaryArithmeticMemberOperatorModel extends IteratorBinaryArithmeticMemberOperator ,
195
+ TaintFunction {
172
196
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
173
- input = this . getIteratorInput ( ) and
197
+ input . isQualifierObject ( ) and
174
198
output .isReturnValue ( )
175
199
}
176
200
}
177
201
178
202
/**
179
- * A non-member `operator-` function that takes a pointer difference type as its second argument .
203
+ * A (member or non-member) `operator+` or `operator -` function for an iterator type.
180
204
*/
181
- class IteratorSubOperator extends Operator {
182
- FunctionInput iteratorInput ;
205
+ class IteratorBinaryAddOperator extends Function {
206
+ IteratorBinaryAddOperator ( ) {
207
+ this instanceof IteratorAddNonMemberOperator or
208
+ this instanceof IteratorBinaryArithmeticMemberOperator
209
+ }
210
+ }
183
211
184
- IteratorSubOperator ( ) {
212
+ /**
213
+ * A non-member `operator-` function that takes a pointer difference type as its second argument.
214
+ */
215
+ class IteratorSubNonMemberOperator extends Operator {
216
+ IteratorSubNonMemberOperator ( ) {
185
217
this .hasName ( "operator-" ) and
186
- iteratorInput = getIteratorArgumentInput ( this , 0 ) and
218
+ exists ( getIteratorArgumentInput ( this , 0 ) ) and
187
219
this .getParameter ( 1 ) .getUnspecifiedType ( ) instanceof IntegralType // not an iterator difference
188
220
}
189
-
190
- FunctionInput getIteratorInput ( ) { result = iteratorInput }
191
221
}
192
222
193
- private class IteratorSubOperatorModel extends IteratorSubOperator , TaintFunction {
223
+ private class IteratorSubOperatorModel extends IteratorSubNonMemberOperator , TaintFunction {
194
224
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
195
- input = this . getIteratorInput ( ) and
225
+ input = getIteratorArgumentInput ( this , 0 ) and
196
226
output .isReturnValue ( )
197
227
}
198
228
}
199
229
200
230
/**
201
231
* A non-member `operator+=` or `operator-=` function for an iterator type.
202
232
*/
203
- class IteratorAssignArithmeticOperator extends Operator {
204
- IteratorAssignArithmeticOperator ( ) {
233
+ class IteratorAssignArithmeticNonMemberOperator extends Operator {
234
+ IteratorAssignArithmeticNonMemberOperator ( ) {
205
235
this .hasName ( [ "operator+=" , "operator-=" ] ) and
206
236
exists ( getIteratorArgumentInput ( this , 0 ) )
207
237
}
208
238
}
209
239
210
- private class IteratorAssignArithmeticOperatorModel extends IteratorAssignArithmeticOperator ,
240
+ private class IteratorAssignArithmeticNonMemberOperatorModel extends IteratorAssignArithmeticNonMemberOperator ,
211
241
DataFlowFunction , TaintFunction {
212
242
override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
213
243
input .isParameter ( 0 ) and
@@ -227,106 +257,102 @@ private class IteratorAssignArithmeticOperatorModel extends IteratorAssignArithm
227
257
}
228
258
229
259
/**
230
- * A prefix `operator*` member function for an iterator type.
231
- */
232
- class IteratorPointerDereferenceMemberOperator extends MemberFunction , TaintFunction ,
233
- IteratorReferenceFunction {
234
- IteratorPointerDereferenceMemberOperator ( ) {
235
- this .getClassAndName ( "operator*" ) instanceof Iterator
236
- }
237
-
238
- override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
239
- input .isQualifierObject ( ) and
240
- output .isReturnValue ( )
241
- or
242
- input .isReturnValueDeref ( ) and
243
- output .isQualifierObject ( )
244
- }
245
- }
246
-
247
- /**
248
- * An `operator++` or `operator--` member function for an iterator type.
260
+ * An `operator+=` or `operator-=` member function of an iterator class.
249
261
*/
250
- class IteratorCrementMemberOperator extends MemberFunction {
251
- IteratorCrementMemberOperator ( ) {
252
- this .getClassAndName ( [ "operator++ " , "operator-- " ] ) instanceof Iterator
262
+ class IteratorAssignArithmeticMemberOperator extends MemberFunction {
263
+ IteratorAssignArithmeticMemberOperator ( ) {
264
+ this .getClassAndName ( [ "operator+= " , "operator-= " ] ) instanceof Iterator
253
265
}
254
266
}
255
267
256
- private class IteratorCrementMemberOperatorModel extends IteratorCrementMemberOperator ,
268
+ private class IteratorAssignArithmeticMemberOperatorModel extends IteratorAssignArithmeticMemberOperator ,
257
269
DataFlowFunction , TaintFunction {
258
270
override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
259
271
input .isQualifierAddress ( ) and
260
272
output .isReturnValue ( )
273
+ }
274
+
275
+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
276
+ input .isQualifierObject ( ) and
277
+ output .isReturnValueDeref ( )
261
278
or
279
+ // reverse flow from returned reference to the qualifier
262
280
input .isReturnValueDeref ( ) and
263
281
output .isQualifierObject ( )
264
282
or
265
- input .isQualifierObject ( ) and
266
- output .isReturnValueDeref ( )
283
+ ( input .isParameter ( 0 ) or input . isParameterDeref ( 0 ) ) and
284
+ output .isQualifierObject ( )
267
285
}
286
+ }
268
287
269
- override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
270
- input .isQualifierObject ( ) and
271
- output .isReturnValueDeref ( )
288
+ /**
289
+ * A (member or non-member) `operator+=` or `operator-=` function for an iterator type.
290
+ */
291
+ class IteratorAssignArithmeticOperator extends Function {
292
+ IteratorAssignArithmeticOperator ( ) {
293
+ this instanceof IteratorAssignArithmeticNonMemberOperator or
294
+ this instanceof IteratorAssignArithmeticMemberOperator
272
295
}
273
296
}
274
297
275
298
/**
276
- * A member `operator->` function for an iterator type.
299
+ * A prefix `operator*` member function for an iterator type.
277
300
*/
278
- private class IteratorFieldMemberOperator extends Operator , TaintFunction {
279
- IteratorFieldMemberOperator ( ) { this .getClassAndName ( "operator->" ) instanceof Iterator }
301
+ class IteratorPointerDereferenceMemberOperator extends MemberFunction , TaintFunction ,
302
+ IteratorReferenceFunction {
303
+ IteratorPointerDereferenceMemberOperator ( ) {
304
+ this .getClassAndName ( "operator*" ) instanceof Iterator
305
+ }
280
306
281
307
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
282
308
input .isQualifierObject ( ) and
283
309
output .isReturnValue ( )
310
+ or
311
+ input .isReturnValueDeref ( ) and
312
+ output .isQualifierObject ( )
284
313
}
285
314
}
286
315
287
316
/**
288
- * An `operator+` or `operator-` member function of an iterator class .
317
+ * A non-member prefix `operator*` function for an iterator type .
289
318
*/
290
- class IteratorBinaryArithmeticMemberOperator extends MemberFunction {
291
- IteratorBinaryArithmeticMemberOperator ( ) {
292
- this .getClassAndName ( [ "operator+" , "operator-" ] ) instanceof Iterator
319
+ class IteratorPointerDereferenceNonMemberOperator extends Operator , IteratorReferenceFunction {
320
+ IteratorPointerDereferenceNonMemberOperator ( ) {
321
+ this .hasName ( "operator*" ) and
322
+ exists ( getIteratorArgumentInput ( this , 0 ) )
293
323
}
294
324
}
295
325
296
- private class IteratorBinaryArithmeticMemberOperatorModel extends IteratorBinaryArithmeticMemberOperator ,
326
+ private class IteratorPointerDereferenceNonMemberOperatorModel extends IteratorPointerDereferenceNonMemberOperator ,
297
327
TaintFunction {
298
328
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
299
- input . isQualifierObject ( ) and
329
+ input = getIteratorArgumentInput ( this , 0 ) and
300
330
output .isReturnValue ( )
331
+ or
332
+ input .isReturnValueDeref ( ) and
333
+ output .isParameterDeref ( 0 )
301
334
}
302
335
}
303
336
304
337
/**
305
- * An `operator+=` or `operator-=` member function of an iterator class .
338
+ * A (member or non-member) prefix `operator*` function for an iterator type .
306
339
*/
307
- class IteratorAssignArithmeticMemberOperator extends MemberFunction {
308
- IteratorAssignArithmeticMemberOperator ( ) {
309
- this .getClassAndName ( [ "operator+=" , "operator-=" ] ) instanceof Iterator
340
+ class IteratorPointerDereferenceOperator extends Function {
341
+ IteratorPointerDereferenceOperator ( ) {
342
+ this instanceof IteratorPointerDereferenceNonMemberOperator or
343
+ this instanceof IteratorPointerDereferenceMemberOperator
310
344
}
311
345
}
312
346
313
- private class IteratorAssignArithmeticMemberOperatorModel extends IteratorAssignArithmeticMemberOperator ,
314
- DataFlowFunction , TaintFunction {
315
- override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
316
- input .isQualifierAddress ( ) and
317
- output .isReturnValue ( )
318
- }
347
+ /**
348
+ * A member `operator->` function for an iterator type.
349
+ */
350
+ private class IteratorFieldMemberOperator extends Operator , TaintFunction {
351
+ IteratorFieldMemberOperator ( ) { this .getClassAndName ( "operator->" ) instanceof Iterator }
319
352
320
353
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
321
354
input .isQualifierObject ( ) and
322
- output .isReturnValueDeref ( )
323
- or
324
- // reverse flow from returned reference to the qualifier
325
- input .isReturnValueDeref ( ) and
326
- output .isQualifierObject ( )
327
- or
328
- ( input .isParameter ( 0 ) or input .isParameterDeref ( 0 ) ) and
329
- output .isQualifierObject ( )
355
+ output .isReturnValue ( )
330
356
}
331
357
}
332
358
0 commit comments