32 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, strdup is transformed to __strdup.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// REQUIRES: (arm-target-arch || armhf-target-arch), fast-unwinder-works11 12// FIXME: We fail to intercept strdup with the dynamic WinASan RTL, so it's not13// in the stack trace.14// XFAIL: win32-dynamic-asan15 16#include <string.h>17 18char kString[] = "foo";19 20int main(int argc, char **argv) {21 char *copy = strdup(kString);22 int x = copy[4 + argc]; // BOOM23 // CHECK: AddressSanitizer: heap-buffer-overflow24 // CHECK: #0 {{.*}}main {{.*}}strdup_oob_test.cpp:[[@LINE-2]]25 // CHECK-LABEL: allocated by thread T{{.*}} here:26 // CHECK: #{{[01]}} {{.*}}strdup27 // CHECK: #{{.*}}main {{.*}}strdup_oob_test.cpp:[[@LINE-6]]28 // CHECK-LABEL: SUMMARY29 // CHECK: strdup_oob_test.cpp:[[@LINE-7]]30 return x;31}32