1 // RUN: %clangxx_asan -g %s -o %t
2 // RUN: not %run %t 1 2>&1 | FileCheck %s --check-prefix=CHECK-FGETS
3 // RUN: not %run %t 2 2>&1 | FileCheck %s --check-prefix=CHECK-FPUTS
4 // RUN: not %run %t 3 2>&1 | FileCheck %s --check-prefix=CHECK-PUTS
11 int test_fgets(const char *testfile
) {
13 FILE *fp
= fopen(testfile
, "r");
15 fgets(buf
, sizeof(buf
) + 1, fp
); // BOOM
21 char buf
[1] = {'x'}; // Note: not nul-terminated
22 FILE *fp
= fopen("/dev/null", "w");
24 fputs(buf
, fp
); // BOOM
30 char *p
= strdup("x");
36 int main(int argc
, char *argv
[]) {
38 int testno
= argv
[1][0] - '0';
40 return test_fgets(argv
[0]);
49 // CHECK-FGETS: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
50 // CHECK-FGETS: #{{.*}} in {{(wrap_|__interceptor_)?}}fgets
51 // CHECK-FPUTS: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
52 // CHECK-FPUTS: #{{.*}} in {{(wrap_|__interceptor_)?}}fputs
53 // CHECK-PUTS: {{.*ERROR: AddressSanitizer: heap-use-after-free}}
54 // CHECK-PUTS: #{{.*}} in {{(wrap_|__interceptor_)?}}puts