| 1 |
// ASan interceptor can be accessed with __interceptor_ prefix. |
| 2 |
|
| 3 |
// { dg-do run { target *-*-linux* *-*-freebsd* } } |
| 4 |
// { dg-options "-fno-builtin-free" } |
| 5 |
// { dg-additional-options "-D__NO_INLINE__" { target { *-*-linux-gnu *-*-freebsd* } } } |
| 6 |
// { dg-shouldfail "asan" } |
| 7 |
|
| 8 |
#include <stdlib.h> |
| 9 |
#include <stdio.h> |
| 10 |
#include <unistd.h> |
| 11 |
|
| 12 |
extern "C" void *__interceptor_malloc(size_t size); |
| 13 |
extern "C" void *malloc(size_t size) { |
| 14 |
write(2, "malloc call\n", sizeof("malloc call\n") - 1); |
| 15 |
return __interceptor_malloc(size); |
| 16 |
} |
| 17 |
|
| 18 |
int main() { |
| 19 |
char *x = (char*)malloc(10); |
| 20 |
free(x); |
| 21 |
return (int)strtol(x, 0, 10); |
| 22 |
} |
| 23 |
|
| 24 |
// { dg-output "malloc call.*(\n|\r\n|\r)" } |
| 25 |
// { dg-output "\[^\n\r]*heap-use-after-free" } |