]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/asan/TestCases/strdup_oob_test.cc
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / test / asan / TestCases / strdup_oob_test.cc
CommitLineData
1a4d82fc
JJ
1// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
5
5bcae85e
SL
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 %s
8
9// Unwind problem on arm: "main" is missing from the allocation stack trace.
10// UNSUPPORTED: armv7l-unknown-linux-gnueabihf
11
1a4d82fc
JJ
12#include <string.h>
13
14char kString[] = "foo";
15
16int main(int argc, char **argv) {
17 char *copy = strdup(kString);
18 int x = copy[4 + argc]; // BOOM
19 // CHECK: AddressSanitizer: heap-buffer-overflow
20 // CHECK: #0 {{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-2]]
92a42be0
SL
21 // CHECK-LABEL: allocated by thread T{{.*}} here:
22 // CHECK: #{{[01]}} {{.*}}strdup
5bcae85e 23 // CHECK: #{{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-6]]
92a42be0 24 // CHECK-LABEL: SUMMARY
5bcae85e 25 // CHECK: strdup_oob_test.cc:[[@LINE-7]]
1a4d82fc
JJ
26 return x;
27}