mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
C++: Test showing no flow through aggregate init
This commit is contained in:
38
cpp/ql/test/library-tests/dataflow/fields/struct_init.c
Normal file
38
cpp/ql/test/library-tests/dataflow/fields/struct_init.c
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
void sink(void *o);
|
||||||
|
void *user_input(void);
|
||||||
|
|
||||||
|
struct AB {
|
||||||
|
void *a;
|
||||||
|
void *b;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Outer {
|
||||||
|
struct AB nestedAB;
|
||||||
|
struct AB *pointerAB;
|
||||||
|
};
|
||||||
|
|
||||||
|
void absink(struct AB *ab) {
|
||||||
|
sink(ab->a); // flow x3 [NOT DETECTED]
|
||||||
|
sink(ab->b); // no flow
|
||||||
|
}
|
||||||
|
|
||||||
|
int struct_init(void) {
|
||||||
|
struct AB ab = { user_input(), 0 };
|
||||||
|
|
||||||
|
sink(ab.a); // flow [NOT DETECTED]
|
||||||
|
sink(ab.b); // no flow
|
||||||
|
absink(&ab);
|
||||||
|
|
||||||
|
struct Outer outer = {
|
||||||
|
{ user_input(), 0 },
|
||||||
|
&ab,
|
||||||
|
};
|
||||||
|
|
||||||
|
sink(outer.nestedAB.a); // flow [NOT DETECTED]
|
||||||
|
sink(outer.nestedAB.b); // no flow
|
||||||
|
sink(outer.pointerAB->a); // flow [NOT DETECTED]
|
||||||
|
sink(outer.pointerAB->b); // no flow
|
||||||
|
|
||||||
|
absink(&outer.nestedAB);
|
||||||
|
absink(outer.pointerAB);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user