• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // If user provides his own libc functions, ASan doesn't
2 // intercept these functions.
3 
4 // RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
5 // RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
6 // RUN: %clangxx_asan -O2 %s -o %t && %run %t 2>&1 | FileCheck %s
7 // RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1 | FileCheck %s
8 // XFAIL: freebsd
9 
10 // On Windows, defining strtoll in a static build results in linker errors, but
11 // it works with the dynamic runtime.
12 // XFAIL: win32-static-asan
13 
14 // On NetBSD, defining strtol in a static build results in linker errors, but
15 // it works with the dynamic runtime.
16 // XFAIL: netbsd && !asan-dynamic-runtime
17 
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 
strtol(const char * nptr,char ** endptr,int base)22 extern "C" long strtol(const char *nptr, char **endptr, int base) {
23   fprintf(stderr, "my_strtol_interceptor\n");
24   if (endptr)
25     *endptr = (char*)nptr + strlen(nptr);
26   return 0;
27 }
28 
main()29 int main() {
30   char *x = (char*)malloc(10 * sizeof(char));
31   free(x);
32   return (int)strtol(x, 0, 10);
33   // CHECK: my_strtol_interceptor
34   // CHECK-NOT: heap-use-after-free
35 }
36