Skip to content

Commit f6d51da

Browse files
committed
C/C++: Fix faulty iterator flow relying on SSA use-use bug.
1 parent 51690fd commit f6d51da

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImplCommon.qll‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ private module IteratorIndirections {
217217
)
218218
}
219219

220+
// A by-value crement result loads the iterator, rather than aliasing its address.
221+
override predicate isAdditionalDereference(Instruction deref, Operand address) {
222+
exists(CallInstruction call |
223+
deref = call and
224+
call.getStaticCallTarget() instanceof Iterator::IteratorCrementMemberOperator and
225+
not call.getResultType() instanceof Cpp::ReferenceType and
226+
address = call.getThisArgumentOperand()
227+
)
228+
}
229+
220230
override predicate isAdditionalConversionFlow(Operand opFrom, Instruction instrTo) {
221231
// This is a bit annoying: Consider the following snippet:
222232
// ```
@@ -255,11 +265,11 @@ private module IteratorIndirections {
255265
store.getDestinationAddress() = var
256266
)
257267
or
258-
// A call to `operator++` or `operator--` is the iterator equivalent version of a
259-
// pointer arithmetic instruction.
268+
// A reference-returning `operator++` or `operator--` preserves the iterator's address.
260269
exists(CallInstruction call |
261270
instrTo = call and
262271
call.getStaticCallTarget() instanceof Iterator::IteratorCrementMemberOperator and
272+
call.getResultType() instanceof Cpp::ReferenceType and
263273
opFrom = call.getThisArgumentOperand()
264274
)
265275
}

0 commit comments

Comments
 (0)