Skip to content

Commit 2ea969d

Browse files
committed
C++: Add tests with missing flow sources.
1 parent 1a811d5 commit 2ea969d

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ extensions:
44
extensible: sourceModel
55
data: # namespace, type, subtypes, name, signature, ext, output, kind, provenance
66
- ["", "", False, "ymlSource", "", "", "ReturnValue", "local", "manual"]
7+
- ["", "", False, "ymlFieldSource", "", "", "ReturnValue.Field[SourceWrapper::value]", "local", "manual"]
8+
- ["", "", False, "source_from_callback_template", "", "", "Argument[0].Parameter[*0].Field[SourceWrapper::value]", "local", "manual"]
9+
- ["", "", False, "source_from_callback_ptr", "", "", "Argument[0].Parameter[*0].Field[SourceWrapper::value]", "local", "manual"]
710
- addsTo:
811
pack: codeql/cpp-all
912
extensible: sinkModel

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@
2323
| test.cpp:201:10:201:10 | x | test-sink |
2424
| test.cpp:218:11:218:11 | x | test-sink |
2525
| test.cpp:224:11:224:11 | c | test-sink |
26+
| test.cpp:243:13:243:17 | value | test-sink |
27+
| test.cpp:248:18:248:22 | value | test-sink |
28+
| test.cpp:254:14:254:18 | value | test-sink |
29+
| test.cpp:258:14:258:18 | value | test-sink |
30+
| test.cpp:263:15:263:19 | value | test-sink |

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,46 @@ void test_reverse_flow(unsigned i, unsigned j) {
223223
char c = s[j];
224224
ymlSink(c); // $ ir
225225
}
226+
}
227+
228+
229+
struct SourceWrapper {
230+
int value;
231+
};
232+
233+
SourceWrapper ymlFieldSource();
234+
235+
template<typename F>
236+
void source_from_callback_template(F);
237+
238+
using Callback = void(*)(const SourceWrapper*);
239+
240+
void source_from_callback_ptr(Callback);
241+
242+
void f(const SourceWrapper* s) {
243+
ymlSink(s->value); // $ MISSING: ir=250:32 ir=251:27
244+
}
245+
246+
void test_source_access_path() {
247+
SourceWrapper wrapper = ymlFieldSource();
248+
ymlSink(wrapper.value); // $ MISSING: ir
249+
250+
source_from_callback_template(f);
251+
source_from_callback_ptr(f);
252+
253+
source_from_callback_template([](const SourceWrapper* s) {
254+
ymlSink(s->value); // $ MISSING: ir
255+
});
256+
257+
source_from_callback_ptr([](const SourceWrapper* s) {
258+
ymlSink(s->value); // $ MISSING: ir
259+
});
260+
261+
struct S {
262+
void operator()(const SourceWrapper* s) {
263+
ymlSink(s->value); // $ MISSING: ir
264+
}
265+
};
266+
267+
source_from_callback_template(S());
226268
}

0 commit comments

Comments
 (0)