1 | // ASan interceptor can be accessed with __interceptor_ prefix. |
2 | |
3 | // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s |
4 | // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s |
5 | // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s |
6 | // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s |
7 | #include <stdlib.h> |
8 | #include <stdio.h> |
9 | |
10 | extern "C" long __interceptor_strtol(const char *nptr, char **endptr, int base); |
11 | extern "C" long strtol(const char *nptr, char **endptr, int base) { |
12 | fprintf(stderr, format: "my_strtol_interceptor\n" ); |
13 | return __interceptor_strtol(nptr, endptr, base); |
14 | } |
15 | |
16 | int main() { |
17 | char *x = (char*)malloc(size: 10 * sizeof(char)); |
18 | free(ptr: x); |
19 | return (int)strtol(nptr: x, endptr: 0, base: 10); |
20 | // CHECK: my_strtol_interceptor |
21 | // CHECK: heap-use-after-free |
22 | } |
23 | |