Skip to content

Commit 67ed12c

Browse files
committed
C++: Correctly model that 'operator->', and 'get'
on smart pointers perform a load.
1 parent b107c4c commit 67ed12c

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private class PointerWrapperTypeIndirection extends Indirection instanceof Point
228228
override predicate isAdditionalDereference(Instruction deref, Operand address) {
229229
exists(CallInstruction call |
230230
operandForFullyConvertedCall(getAUse(deref), call) and
231-
this = call.getStaticCallTarget().getClassAndName("operator*") and
231+
this = call.getStaticCallTarget().getClassAndName(["operator*", "operator->", "get"]) and
232232
address = call.getThisArgumentOperand()
233233
)
234234
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-ir-consistency.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ reverseRead
2020
argHasPostUpdate
2121
postWithInFlow
2222
| test.cpp:384:10:384:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
23-
| test.cpp:384:10:384:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
24-
| test.cpp:391:10:391:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
2523
| test.cpp:391:10:391:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
2624
| test.cpp:400:10:400:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
27-
| test.cpp:400:10:400:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
28-
| test.cpp:407:10:407:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
2925
| test.cpp:407:10:407:13 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
3026
viableImplInCallContextTooLarge
3127
uniqueParameterNodeAtPosition

cpp/ql/test/library-tests/dataflow/fields/dataflow-ir-consistency.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ reverseRead
4444
argHasPostUpdate
4545
postWithInFlow
4646
| realistic.cpp:54:16:54:47 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
47-
| realistic.cpp:54:16:54:47 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
48-
| realistic.cpp:60:16:60:18 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
4947
| realistic.cpp:60:16:60:18 | memcpy output argument | PostUpdateNode should not be the target of local flow. |
5048
viableImplInCallContextTooLarge
5149
uniqueParameterNodeAtPosition

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ struct B {
8585

8686
void test_operator_arrow(std::unique_ptr<A> p, std::unique_ptr<B> q) {
8787
p->x = source();
88-
sink(p->x); // $ ast MISSING: ir
88+
sink(p->x); // $ ast,ir
8989
sink(p->y);
9090

9191
q->a1.x = source();
92-
sink(q->a1.x); // $ ast MISSING: ir
92+
sink(q->a1.x); // $ ast,ir
9393
sink(q->a1.y);
9494
sink(q->a2.x);
9595
}
@@ -101,7 +101,7 @@ void taint_x(A* pa) {
101101
void reverse_taint_smart_pointer() {
102102
std::unique_ptr<A> p = std::unique_ptr<A>(new A);
103103
taint_x(p.get());
104-
sink(p->x); // $ ast MISSING: ir
104+
sink(p->x); // $ ast,ir
105105
}
106106

107107
struct C {
@@ -131,7 +131,7 @@ int nested_shared_ptr_taint(std::shared_ptr<C> p1, std::unique_ptr<std::shared_p
131131

132132
int nested_shared_ptr_taint_cref(std::shared_ptr<C> p1, std::unique_ptr<std::shared_ptr<int>> p2) {
133133
taint_x_shared_cref(p1->q);
134-
sink(p1->q->x); // $ ast MISSING: ir
134+
sink(p1->q->x); // $ ast,ir
135135

136136
getNumberCRef(*p2);
137137
sink(**p2); // $ ast,ir

0 commit comments

Comments
 (0)