C++: Test definitions through &, *, ...

This commit is contained in:
Jonas Jensen
2020-04-21 11:30:07 +02:00
parent 4ddf12119d
commit 5f74c24d4d
6 changed files with 272 additions and 2 deletions

View File

@@ -68,3 +68,70 @@ void test_nonMemberSetA() {
nonMemberSetA(&s, user_input());
sink(nonMemberGetA(&s)); // flow
}
////////////////////
struct Inner {
void *a;
};
struct Outer {
Inner inner_nested, *inner_ptr;
void *a;
};
void taint_inner_a_ptr(Inner *inner) {
inner->a = user_input();
}
void taint_inner_a_ref(Inner &inner) {
inner.a = user_input();
}
void taint_a_ptr(void **pa) {
*pa = user_input();
}
void taint_a_ref(void *&pa) {
pa = user_input();
}
void test_outer_with_ptr(Outer *pouter) {
Outer outer;
taint_inner_a_ptr(&outer.inner_nested);
taint_inner_a_ptr(outer.inner_ptr);
taint_a_ptr(&outer.a);
taint_inner_a_ptr(&pouter->inner_nested);
taint_inner_a_ptr(pouter->inner_ptr);
taint_a_ptr(&pouter->a);
sink(outer.inner_nested.a); // flow [NOT DETECTED by AST]
sink(outer.inner_ptr->a); // flow [NOT DETECTED by IR]
sink(outer.a); // flow [NOT DETECTED]
sink(pouter->inner_nested.a); // flow [NOT DETECTED by AST]
sink(pouter->inner_ptr->a); // flow [NOT DETECTED by IR]
sink(pouter->a); // flow [NOT DETECTED]
}
void test_outer_with_ref(Outer *pouter) {
Outer outer;
taint_inner_a_ref(outer.inner_nested);
taint_inner_a_ref(*outer.inner_ptr);
taint_a_ref(outer.a);
taint_inner_a_ref(pouter->inner_nested);
taint_inner_a_ref(*pouter->inner_ptr);
taint_a_ref(pouter->a);
sink(outer.inner_nested.a); // flow
sink(outer.inner_ptr->a); // flow [NOT DETECTED]
sink(outer.a); // flow [NOT DETECTED by IR]
sink(pouter->inner_nested.a); // flow
sink(pouter->inner_ptr->a); // flow [NOT DETECTED]
sink(pouter->a); // flow [NOT DETECTED by IR]
}