88import cpp
99import semmle.code.cpp.models.interfaces.Taint
1010import semmle.code.cpp.models.interfaces.DataFlow
11+ import semmle.code.cpp.models.interfaces.Iterator
1112
1213/**
1314 * An instantiation of the `std::iterator_traits` template.
@@ -80,7 +81,7 @@ private FunctionInput getIteratorArgumentInput(Operator op, int index) {
8081/**
8182 * A non-member prefix `operator*` function for an iterator type.
8283 */
83- class IteratorPointerDereferenceOperator extends Operator , TaintFunction {
84+ class IteratorPointerDereferenceOperator extends Operator , TaintFunction , IteratorReferenceFunction {
8485 FunctionInput iteratorInput ;
8586
8687 IteratorPointerDereferenceOperator ( ) {
@@ -92,6 +93,8 @@ class IteratorPointerDereferenceOperator extends Operator, TaintFunction {
9293 input = iteratorInput and
9394 output .isReturnValue ( )
9495 }
96+
97+ override FunctionInput getIteratorInput ( ) { result = iteratorInput }
9598}
9699
97100/**
@@ -169,12 +172,15 @@ class IteratorAssignArithmeticOperator extends Operator, DataFlowFunction, Taint
169172/**
170173 * A prefix `operator*` member function for an iterator type.
171174 */
172- class IteratorPointerDereferenceMemberOperator extends MemberFunction , TaintFunction {
175+ class IteratorPointerDereferenceMemberOperator extends MemberFunction , TaintFunction ,
176+ IteratorReferenceFunction {
173177 IteratorPointerDereferenceMemberOperator ( ) {
174178 this .hasName ( "operator*" ) and
175179 this .getDeclaringType ( ) instanceof Iterator
176180 }
177181
182+ override FunctionInput getIteratorInput ( ) { result .isQualifierObject ( ) }
183+
178184 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
179185 input .isQualifierObject ( ) and
180186 output .isReturnValue ( )
@@ -260,7 +266,7 @@ class IteratorAssignArithmeticMemberOperator extends MemberFunction, DataFlowFun
260266/**
261267 * An `operator[]` member function of an iterator class.
262268 */
263- class IteratorArrayMemberOperator extends MemberFunction , TaintFunction {
269+ class IteratorArrayMemberOperator extends MemberFunction , TaintFunction , IteratorReferenceFunction {
264270 IteratorArrayMemberOperator ( ) {
265271 this .hasName ( "operator[]" ) and
266272 this .getDeclaringType ( ) instanceof Iterator
@@ -270,6 +276,8 @@ class IteratorArrayMemberOperator extends MemberFunction, TaintFunction {
270276 input .isQualifierObject ( ) and
271277 output .isReturnValue ( )
272278 }
279+
280+ override FunctionInput getIteratorInput ( ) { result .isQualifierObject ( ) }
273281}
274282
275283/**
0 commit comments