| 1 |
#include "analyzer-decls.h" |
| 2 |
#include <stdio.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <string.h> |
| 5 |
|
| 6 |
struct foo |
| 7 |
{ |
| 8 |
int num; |
| 9 |
}; |
| 10 |
|
| 11 |
/* malloc with tainted size from a field. */ |
| 12 |
|
| 13 |
void *test_1 (FILE *f) |
| 14 |
{ |
| 15 |
struct foo tmp; |
| 16 |
fread(&tmp, sizeof(tmp), 1, f); /* { dg-message "\\(\[0-9\]+\\) 'tmp' gets an unchecked value here" "event: tmp gets unchecked value" { xfail *-*-* } } */ |
| 17 |
|
| 18 |
__analyzer_dump_state ("taint", tmp.num); /* { dg-warning "state: 'tainted'" } */ |
| 19 |
__analyzer_dump_state ("taint", tmp.num * 16); /* { dg-warning "state: 'tainted'" } */ |
| 20 |
|
| 21 |
return malloc (tmp.num * 16); /* { dg-warning "use of attacker-controlled value 'tmp\\.num \\* 16' as allocation size without upper-bounds checking" "warning" } */ |
| 22 |
/* { dg-message "\\(\[0-9\]+\\) use of attacker-controlled value 'tmp\\.num \\* 16' as allocation size without upper-bounds checking" "final event with expr" { target *-*-* } .-1 } */ |
| 23 |
// TODO: show where tmp.num * 16 gets the bogus value |
| 24 |
} |