Skip to content

Commit 6c76428

Browse files
committed
C++: Add taint model and accept test changes.
1 parent 54c6f47 commit 6c76428

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

  • cpp/ql

cpp/ql/lib/semmle/code/cpp/models/implementations/SmartPointer.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ private class MakeUniqueOrShared extends TaintFunction {
106106
*
107107
* This could be a constructor, an assignment operator, or a named member function like `reset()`.
108108
*/
109-
private class SmartPtrSetterFunction extends MemberFunction, AliasFunction, SideEffectFunction {
109+
private class SmartPtrSetterFunction extends MemberFunction, AliasFunction, SideEffectFunction,
110+
TaintFunction
111+
{
110112
SmartPtrSetterFunction() {
111113
this.getDeclaringType() instanceof SmartPtr and
112114
not this.isStatic() and
@@ -158,6 +160,16 @@ private class SmartPtrSetterFunction extends MemberFunction, AliasFunction, Side
158160
output.isReturnValue()
159161
}
160162

163+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
164+
exists(Parameter param0, Type t, int indirectionIndex |
165+
param0 = this.getParameter(0) and
166+
param0.getUnspecifiedType().(PointerType).getBaseType() = t and
167+
this.getTemplateArgument(0) = t and
168+
input.isParameterDeref(0, indirectionIndex) and
169+
output.isQualifierObject(indirectionIndex + 1)
170+
)
171+
}
172+
161173
private FunctionInput getPointerInput() {
162174
exists(Parameter param0 | param0 = this.getParameter(0) |
163175
(

cpp/ql/test/library-tests/dataflow/smart-pointers-taint/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void test_shared_ptr_int() {
3131
std::shared_ptr<int> p1(new int(source()));
3232
std::shared_ptr<int> p2 = std::make_shared<int>(source());
3333

34-
sink(*p1); // $ ast MISSING: ir
34+
sink(*p1); // $ ast ir
3535
sink(*p2); // $ ast ir
3636
}
3737

0 commit comments

Comments
 (0)