Skip to content

Commit 559c799

Browse files
committed
C++: Also recognize iterators obtained via a function that doesn't receive the container as a qualiifer.
1 parent 77250af commit 559c799

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ cached
463463
private module Cached {
464464
private import semmle.code.cpp.models.interfaces.Iterator as Interfaces
465465
private import semmle.code.cpp.models.implementations.Iterator as Iterator
466+
private import semmle.code.cpp.models.interfaces.FunctionInputsAndOutputs as IO
466467

467468
/**
468469
* Holds if `next` is a instruction with a memory result that potentially
@@ -593,11 +594,16 @@ private module Cached {
593594
private predicate isChiAfterBegin(
594595
BaseSourceVariableInstruction containerBase, StoreInstruction iterator
595596
) {
596-
exists(CallInstruction getIterator |
597+
exists(
598+
CallInstruction getIterator, Iterator::GetIteratorFunction getIteratorFunction,
599+
IO::FunctionInput input, int i
600+
|
597601
getIterator = iterator.getSourceValue() and
598-
getIterator.getStaticCallTarget() instanceof Iterator::GetIteratorFunction and
602+
getIteratorFunction = getIterator.getStaticCallTarget() and
603+
getIteratorFunction.getsIterator(input, _) and
599604
isDef(_, any(Node0Impl n | n.asInstruction() = iterator), _, _, 1, 0) and
600-
isUse(_, getIterator.getThisArgumentOperand(), containerBase, 0, 0)
605+
input.isParameterDerefOrQualifierObject(i) and
606+
isUse(_, getIterator.getArgumentOperand(i), containerBase, 0, 0)
601607
)
602608
}
603609

cpp/ql/test/library-tests/dataflow/taint-tests/vector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ void test_vector_inserter(char *source_string) {
426426
std::vector<std::string> out;
427427
auto it = std::back_inserter(out);
428428
*it++ = std::string(source_string);
429-
sink(out); // $ ast MISSING: ir
429+
sink(out); // $ ast,ir
430430
}
431431

432432
{
433433
std::vector<int> out;
434434
auto it = std::back_inserter(out);
435435
*it++ = source();
436-
sink(out); // $ ast MISSING: ir
436+
sink(out); // $ ast,ir
437437
}
438438

439439
{

0 commit comments

Comments
 (0)