Skip to content

Commit 48628fa

Browse files
authored
Merge pull request #4589 from criemen/model-vector-emplace
C++: Model std::vector emplace and emplace_back()
2 parents b5063bb + e7e5754 commit 48628fa

File tree

6 files changed

+188
-119
lines changed

6 files changed

+188
-119
lines changed

cpp/ql/src/semmle/code/cpp/models/implementations/StdContainer.qll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,34 @@ class StdSequenceContainerAt extends TaintFunction {
206206
output.isQualifierObject()
207207
}
208208
}
209+
210+
/**
211+
* The standard vector `emplace` function.
212+
*/
213+
class StdVectorEmplace extends TaintFunction {
214+
StdVectorEmplace() { this.hasQualifiedName("std", "vector", "emplace") }
215+
216+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
217+
// flow from any parameter except the position iterator to qualifier and return value
218+
// (here we assume taint flow from any constructor parameter to the constructed object)
219+
input.isParameter([1 .. getNumberOfParameters() - 1]) and
220+
(
221+
output.isQualifierObject() or
222+
output.isReturnValue()
223+
)
224+
}
225+
}
226+
227+
/**
228+
* The standard vector `emplace_back` function.
229+
*/
230+
class StdVectorEmplaceBack extends TaintFunction {
231+
StdVectorEmplaceBack() { this.hasQualifiedName("std", "vector", "emplace_back") }
232+
233+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
234+
// flow from any parameter to qualifier
235+
// (here we assume taint flow from any constructor parameter to the constructed object)
236+
input.isParameter([0 .. getNumberOfParameters() - 1]) and
237+
output.isQualifierObject()
238+
}
239+
}

0 commit comments

Comments
 (0)