12d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
22d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
32d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
42d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov
6d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov#include <string.h>
7d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov
8d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonovchar kString[] = "foo";
9d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov
10d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonovint main(int argc, char **argv) {
11d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov  char *copy = strdup(kString);
12d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov  int x = copy[4 + argc];  // BOOM
13d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov  // CHECK: AddressSanitizer: heap-buffer-overflow
14d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov  // CHECK: #0 {{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-2]]
155d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines  // CHECK-LABEL: allocated by thread T{{.*}} here:
165d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines  // CHECK: #{{[01]}} {{.*}}strdup
175d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines  // CHECK-LABEL: SUMMARY
18d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov  // CHECK: strdup_oob_test.cc:[[@LINE-6]]
19d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov  return x;
20d530d892b4958a9ae54e57472d5d0a0bae1f6ad8Alexey Samsonov}
21