C++: Add tests to demo lack dataflow by reference

This commit is contained in:
Jonas Jensen
2019-02-26 21:15:51 +01:00
parent 86e646beb4
commit 20f3df0d09
5 changed files with 50 additions and 0 deletions

View File

@@ -423,3 +423,35 @@ class FlowThroughFields {
sink(field); // tainted
}
};
typedef unsigned long size_t;
void *memcpy(void *dest, const void *src, size_t count);
void flowThroughMemcpy_ssa_with_local_flow(int source1) {
int tmp = 0;
memcpy(&tmp, &source1, sizeof tmp);
sink(tmp); // tainted (FALSE NEGATIVE)
}
void flowThroughMemcpy_blockvar_with_local_flow(int source1, int b) {
int tmp = 0;
int *capture = &tmp;
memcpy(&tmp, &source1, sizeof tmp);
sink(tmp); // tainted (FALSE NEGATIVE)
if (b) {
sink(tmp); // different sub-basic-block
}
}
void cleanedByMemcpy_ssa(int clean1) {
int tmp;
memcpy(&tmp, &clean1, sizeof tmp);
sink(tmp); // clean
}
void cleanedByMemcpy_blockvar(int clean1) {
int tmp;
int *capture = &tmp;
memcpy(&tmp, &clean1, sizeof tmp);
sink(tmp); // clean (FALSE POSITIVE)
}