Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1dae8f6

Browse files
author
Dave Bartolomeo
committed
Model copy-ish constructors for std::pair
1 parent 1b53c46 commit 1dae8f6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • cpp/ql/src/semmle/code/cpp/models/implementations

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@
44

55
import semmle.code.cpp.models.interfaces.Taint
66

7+
/**
8+
* An instantiation of `std::pair<T1, T2>`.
9+
*/
10+
class StdPairClass extends ClassTemplateInstantiation {
11+
StdPairClass() { getTemplate().hasQualifiedName("std", "pair") }
12+
}
13+
14+
/**
15+
* Any of the single-parameter constructors of `std::pair` that takes a reference to an
16+
* instantiation of `std::pair`. These constructors allow conversion between pair types when the
17+
* underlying element types are convertible.
18+
*/
19+
class StdPairCopyishConstructor extends Constructor, TaintFunction {
20+
StdPairCopyishConstructor() {
21+
this.getDeclaringType() instanceof StdPairClass and
22+
this.getNumberOfParameters() = 1 and
23+
this.getParameter(0).getUnspecifiedType().(ReferenceType).getBaseType().getUnspecifiedType()
24+
instanceof StdPairClass
25+
}
26+
27+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
28+
// taint flow from the source object to the constructed object
29+
input.isParameterDeref(0) and
30+
(
31+
output.isReturnValue()
32+
or
33+
output.isQualifierObject()
34+
)
35+
}
36+
}
37+
738
/**
839
* Additional model for `std::pair` constructors.
940
*/

0 commit comments

Comments
 (0)