mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
C++: Add tests to demo lack dataflow by reference
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user