| 1 |
#include "analyzer-decls.h" |
| 2 |
#include <stdio.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <string.h> |
| 5 |
|
| 6 |
/* malloc with tainted size from a syscall. */ |
| 7 |
|
| 8 |
struct arg_buf |
| 9 |
{ |
| 10 |
size_t sz; |
| 11 |
}; |
| 12 |
|
| 13 |
void *p; |
| 14 |
|
| 15 |
void __attribute__((tainted_args)) |
| 16 |
test_1 (void *data) /* { dg-message "\\(1\\) function 'test_1' marked with '__attribute__\\(\\(tainted_args\\)\\)'" } */ |
| 17 |
{ |
| 18 |
/* we should treat pointed-to-structs as tainted. */ |
| 19 |
__analyzer_dump_state ("taint", data); /* { dg-warning "state: 'tainted'" } */ |
| 20 |
|
| 21 |
struct arg_buf *args = data; |
| 22 |
|
| 23 |
__analyzer_dump_state ("taint", args); /* { dg-warning "state: 'tainted'" } */ |
| 24 |
__analyzer_dump_state ("taint", args->sz); /* { dg-warning "state: 'tainted'" } */ |
| 25 |
|
| 26 |
p = malloc (args->sz); /* { dg-warning "use of attacker-controlled value '\[^'\]*.sz' as allocation size without upper-bounds checking" "warning" } */ |
| 27 |
/* { dg-message "\\(\[0-9\]+\\) use of attacker-controlled value '\[^'\]*.sz' as allocation size without upper-bounds checking" "final event" { target *-*-* } .-1 } */ |
| 28 |
} |