Skip to content

Commit 256ae2f

Browse files
committed
C++: Add test demonstrating a flow not detected
1 parent 79811fc commit 256ae2f

File tree

1 file changed

+43
-0
lines changed
  • cpp/ql/test/library-tests/dataflow/dataflow-tests

1 file changed

+43
-0
lines changed

cpp/ql/test/library-tests/dataflow/dataflow-tests/dispatch.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,46 @@ namespace virtual_inheritance {
130130
sink(topRef.isSource()); // flow [NOT DETECTED]
131131
}
132132
}
133+
134+
union union_with_sink_fun_ptrs {
135+
SinkFunctionType f;
136+
SinkFunctionType g;
137+
} u;
138+
139+
void call_sink_through_union_field_f(SinkFunctionType func) {
140+
func(source());
141+
}
142+
143+
void call_sink_through_union_field_g(SinkFunctionType func) {
144+
func(source());
145+
}
146+
147+
void set_global_union_field_f() {
148+
u.f = callSink;
149+
}
150+
151+
void test_call_sink_through_union() {
152+
set_global_union_field_f();
153+
call_sink_through_union_field_f(u.f);
154+
call_sink_through_union_field_g(u.g);
155+
}
156+
157+
union { union_with_sink_fun_ptrs u; } u2;
158+
159+
void call_sink_through_union_field_u_g(SinkFunctionType func) {
160+
func(source());
161+
}
162+
163+
void call_sink_through_union_field_u_f(SinkFunctionType func) {
164+
func(source());
165+
}
166+
167+
void set_global_union_field_u_f() {
168+
u2.u.f = callSink;
169+
}
170+
171+
void test_call_sink_through_union_2() {
172+
set_global_union_field_u_f();
173+
call_sink_through_union_field_u_f(u2.u.f); // flow [NOT DETECTED]
174+
call_sink_through_union_field_u_g(u2.u.g); // flow [NOT DETECTED]
175+
}

0 commit comments

Comments
 (0)