1// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
2// RUN: not %run %t 2>&1 | FileCheck %s
3//
4// REQUIRES: stable-runtime
5// MSVC doesn't support VLAs
6// UNSUPPORTED: msvc
7
8#include "defines.h"
9#include <assert.h>
10#include <stdint.h>
11
12ATTRIBUTE_NOINLINE void foo(int index, int len) {
13 if (index > len) {
14 char str[len];
15 assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
16 str[index] = '1'; // BOOM
17// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
18// CHECK: WRITE of size 1 at [[ADDR]] thread T0
19 }
20}
21
22int main(int argc, char **argv) {
23 foo(index: 33, len: 10);
24 return 0;
25}
26

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of compiler-rt/test/asan/TestCases/vla_condition_overflow.cpp