28 lines · cpp
1// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s2// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s3// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s4// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s5 6// When built as C on Linux, strndup is transformed to __strndup.7// RUN: %clangxx_asan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck %s8 9// Unwind problem on arm: "main" is missing from the allocation stack trace.10// UNSUPPORTED: target={{.*windows-msvc.*}},target=s390{{.*}},target=arm{{.*}} && !fast-unwinder-works11 12#include <string.h>13 14char kString[] = "foo";15 16int main(int argc, char **argv) {17 char *copy = strndup(kString, 2);18 int x = copy[2 + argc]; // BOOM19 // CHECK: AddressSanitizer: heap-buffer-overflow20 // CHECK: #0 {{.*}}main {{.*}}strndup_oob_test.cpp:[[@LINE-2]]21 // CHECK-LABEL: allocated by thread T{{.*}} here:22 // CHECK: #{{[01]}} {{.*}}strndup23 // CHECK: #{{.*}}main {{.*}}strndup_oob_test.cpp:[[@LINE-6]]24 // CHECK-LABEL: SUMMARY25 // CHECK: strndup_oob_test.cpp:[[@LINE-7]]26 return x;27}28