Skip to content

Commit 6736dd4

Browse files
committed
C++: Add some tests with missing flow through function objects.
1 parent 3a0def7 commit 6736dd4

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed

cpp/ql/test/library-tests/dataflow/external-models/flow.ext.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ extensions:
1616
- ["", "", False, "ymlStepManual", "", "", "Argument[0]", "ReturnValue", "taint", "manual"]
1717
- ["", "", False, "ymlStepGenerated", "", "", "Argument[0]", "ReturnValue", "taint", "df-generated"]
1818
- ["", "", False, "ymlStepManual_with_body", "", "", "Argument[0]", "ReturnValue", "taint", "manual"]
19-
- ["", "", False, "ymlStepGenerated_with_body", "", "", "Argument[0]", "ReturnValue", "taint", "df-generated"]
19+
- ["", "", False, "ymlStepGenerated_with_body", "", "", "Argument[0]", "ReturnValue", "taint", "df-generated"]
20+
- ["", "", False, "callWithArgument", "", "", "Argument[1]", "Argument[0].Parameter[0]", "value", "manual"]

cpp/ql/test/library-tests/dataflow/external-models/sinks.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
| test.cpp:33:10:33:11 | z2 | test-sink |
1010
| test.cpp:36:10:36:11 | z3 | test-sink |
1111
| test.cpp:48:16:48:16 | x | test-sink |
12+
| test.cpp:69:11:69:11 | y | test-sink |
13+
| test.cpp:75:11:75:11 | y | test-sink |
14+
| test.cpp:83:11:83:11 | y | test-sink |
15+
| test.cpp:89:11:89:11 | y | test-sink |

cpp/ql/test/library-tests/dataflow/external-models/sources.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| asio_streams.cpp:87:34:87:44 | read_until output argument | remote |
22
| test.cpp:10:10:10:18 | call to ymlSource | local |
33
| test.cpp:56:8:56:16 | call to ymlSource | local |
4+
| test.cpp:94:10:94:18 | call to ymlSource | local |
45
| windows.cpp:22:15:22:29 | *call to GetCommandLineA | local |
56
| windows.cpp:34:17:34:38 | *call to GetEnvironmentStringsA | local |
67
| windows.cpp:39:36:39:38 | GetEnvironmentVariableA output argument | local |

cpp/ql/test/library-tests/dataflow/external-models/test.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,48 @@ int test_pthread_create() {
5858
pthread_t threadId;
5959
pthread_create(&threadId, nullptr, myThreadFunction, (void *)&s);
6060
}
61+
62+
template<typename F>
63+
void callWithArgument(F f, int x);
64+
65+
struct StructWithOperatorCall_has_constructor {
66+
StructWithOperatorCall_has_constructor();
67+
68+
void operator()(int y) {
69+
ymlSink(y); // $ MISSING: ir
70+
}
71+
};
72+
73+
struct StructWithOperatorCall_no_constructor {
74+
void operator()(int y) {
75+
ymlSink(y); // $ MISSING: ir
76+
}
77+
};
78+
79+
struct StructWithOperatorCall_has_constructor_2 {
80+
StructWithOperatorCall_has_constructor_2();
81+
82+
void operator()(int y) {
83+
ymlSink(y); // $ MISSING: ir
84+
}
85+
};
86+
87+
struct StructWithOperatorCall_no_constructor_2 {
88+
void operator()(int y) {
89+
ymlSink(y); // $ MISSING: ir
90+
}
91+
};
92+
93+
void test_callWithArgument() {
94+
int x = ymlSource();
95+
{
96+
StructWithOperatorCall_has_constructor func;
97+
callWithArgument(func, x);
98+
}
99+
{
100+
StructWithOperatorCall_no_constructor func;
101+
callWithArgument(func, x);
102+
}
103+
callWithArgument(StructWithOperatorCall_has_constructor_2(), x);
104+
callWithArgument(StructWithOperatorCall_no_constructor_2(), x);
105+
}

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7777,17 +7777,24 @@ WARNING: module 'TaintTracking' has been deprecated and may be removed in future
77777777
| thread.cpp:24:5:24:5 | s | thread.cpp:26:38:26:38 | s | |
77787778
| thread.cpp:24:5:24:5 | s | thread.cpp:27:37:27:37 | s | |
77797779
| thread.cpp:24:5:24:5 | s | thread.cpp:28:38:28:38 | s | |
7780+
| thread.cpp:24:5:24:5 | s | thread.cpp:32:7:32:7 | s | |
77807781
| thread.cpp:25:3:25:3 | s [post update] | thread.cpp:26:38:26:38 | s | |
77817782
| thread.cpp:25:3:25:3 | s [post update] | thread.cpp:27:37:27:37 | s | |
77827783
| thread.cpp:25:3:25:3 | s [post update] | thread.cpp:28:38:28:38 | s | |
7784+
| thread.cpp:25:3:25:3 | s [post update] | thread.cpp:32:7:32:7 | s | |
77837785
| thread.cpp:25:3:25:16 | ... = ... | thread.cpp:25:5:25:5 | x [post update] | |
77847786
| thread.cpp:25:9:25:14 | call to source | thread.cpp:25:3:25:16 | ... = ... | |
7785-
| thread.cpp:26:18:26:39 | call to thread | thread.cpp:29:1:29:1 | t1 | |
7787+
| thread.cpp:26:18:26:39 | call to thread | thread.cpp:33:1:33:1 | t1 | |
77867788
| thread.cpp:26:38:26:38 | s | thread.cpp:26:37:26:38 | & ... | |
7787-
| thread.cpp:27:18:27:38 | call to thread | thread.cpp:29:1:29:1 | t2 | |
7789+
| thread.cpp:27:18:27:38 | call to thread | thread.cpp:33:1:33:1 | t2 | |
77887790
| thread.cpp:27:37:27:37 | ref arg s | thread.cpp:28:38:28:38 | s | |
7789-
| thread.cpp:28:18:28:43 | call to thread | thread.cpp:29:1:29:1 | t3 | |
7791+
| thread.cpp:27:37:27:37 | ref arg s | thread.cpp:32:7:32:7 | s | |
7792+
| thread.cpp:28:18:28:43 | call to thread | thread.cpp:33:1:33:1 | t3 | |
77907793
| thread.cpp:28:38:28:38 | s | thread.cpp:28:37:28:38 | & ... | |
7794+
| thread.cpp:30:18:32:8 | call to thread | thread.cpp:33:1:33:1 | t4 | |
7795+
| thread.cpp:30:24:30:24 | p | thread.cpp:30:24:30:24 | p | |
7796+
| thread.cpp:30:24:30:24 | p | thread.cpp:31:10:31:10 | p | |
7797+
| thread.cpp:32:7:32:7 | s | thread.cpp:32:6:32:7 | & ... | |
77917798
| vector.cpp:16:43:16:49 | source1 | vector.cpp:17:26:17:32 | source1 | |
77927799
| vector.cpp:16:43:16:49 | source1 | vector.cpp:31:38:31:44 | source1 | |
77937800
| vector.cpp:17:21:17:33 | call to vector | vector.cpp:19:14:19:14 | v | |

cpp/ql/test/library-tests/dataflow/taint-tests/test_mad-signatures.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46936,6 +46936,8 @@ getParameterTypeName
4693646936
| stl.h:690:12:690:17 | thread | 0 | func:0 && |
4693746937
| stl.h:690:12:690:17 | thread | 0 | func:0 && |
4693846938
| stl.h:690:12:690:17 | thread | 0 | func:0 && |
46939+
| stl.h:690:12:690:17 | thread | 0 | func:0 && |
46940+
| stl.h:690:12:690:17 | thread | 1 | func:1 && |
4693946941
| stl.h:690:12:690:17 | thread | 1 | func:1 && |
4694046942
| stl.h:690:12:690:17 | thread | 1 | func:1 && |
4694146943
| stl.h:690:12:690:17 | thread | 1 | func:1 && |
@@ -47196,6 +47198,11 @@ getParameterTypeName
4719647198
| thread.cpp:14:6:14:22 | thread_function_2 | 0 | S |
4719747199
| thread.cpp:18:6:18:22 | thread_function_3 | 0 | S * |
4719847200
| thread.cpp:18:6:18:22 | thread_function_3 | 1 | int |
47201+
| thread.cpp:30:18:30:18 | (unnamed constructor) | 0 | const lambda [] type at line 762, col. 18 & |
47202+
| thread.cpp:30:18:30:18 | (unnamed constructor) | 0 | lambda [] type at line 762, col. 18 && |
47203+
| thread.cpp:30:18:30:18 | operator= | 0 | const lambda [] type at line 762, col. 18 & |
47204+
| thread.cpp:30:20:30:20 | _FUN | 0 | S * |
47205+
| thread.cpp:30:20:30:20 | operator() | 0 | S * |
4719947206
| vector.cpp:13:6:13:9 | sink | 0 | int |
4720047207
| vector.cpp:14:27:14:30 | sink | 0 | vector> & |
4720147208
| vector.cpp:14:27:14:30 | sink | 0 | vector> & |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ void test_thread() {
2626
std::thread t1(thread_function_1, &s);
2727
std::thread t2(thread_function_2, s);
2828
std::thread t3(thread_function_3, &s, 42);
29+
30+
std::thread t4([](S* p) {
31+
sink(p->x); // $ MISSING: ir
32+
}, &s);
2933
}

0 commit comments

Comments
 (0)