brintos

brintos / llvm-project-archived public Read only

0
0
Text · 730 B · 6ee6b54 Raw
27 lines · cpp
1// REQUIRES: gwp_asan2// RUN: %clangxx_gwp_asan %s -o %t3// RUN: %expect_crash %run %t 2>&1 | FileCheck %s4 5// RUN: %clangxx_gwp_asan %s -o %t -DTOUCH_GUARD_PAGE6// RUN: %expect_crash %run %t 2>&1 | FileCheck %s7 8// CHECK: GWP-ASan detected a memory error9// CHECK: Use After Free10// CHECK-SAME: warning: buffer overflow/underflow detected on a free()'d allocation11// CHECK-SAME: at 0x{{[a-f0-9]+}} ({{[0-9]+}} byte{{s?}} to the right12 13#include <cstdlib>14 15#include "page_size.h"16 17int main() {18  unsigned malloc_size = 1;19#ifdef TOUCH_GUARD_PAGE20  malloc_size = pageSize();21#endif // TOUCH_GUARD_PAGE22  char *Ptr = reinterpret_cast<char *>(malloc(malloc_size));23  free(Ptr);24  volatile char x = *(Ptr + malloc_size);25  return 0;26}27