brintos

brintos / llvm-project-archived public Read only

0
0
Text · 942 B · a80ab09 Raw
32 lines · cpp
1// RUN: %clang_cl_asan %Od %s %Fe%t2// RUN: not %run %t 2>&1 | FileCheck %s3 4#include <stdio.h>5#include <string.h>6 7void call_memcpy(void* (*f)(void *, const void *, size_t),8                 void *a, const void *b, size_t c) {9  f(a, b, c);10}11 12int main() {13  char buff1[6] = "Hello", buff2[5];14 15  call_memcpy(&memcpy, buff2, buff1, 5);16  if (buff1[2] != buff2[2])17    return 2;18  printf("Initial test OK\n");19  fflush(0);20// CHECK: Initial test OK21 22  call_memcpy(&memcpy, buff2, buff1, 6);23// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]24// CHECK: WRITE of size 6 at [[ADDR]] thread T025// CHECK-NEXT:  mem{{.*}}26// CHECK-NEXT:  call_mem{{.*}}27// CHECK-NEXT:  main {{.*}}intercept_memcpy.cpp:[[@LINE-5]]28// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame29// CHECK-NEXT:   #0 {{.*}} main30// CHECK: 'buff2'{{.*}} <== Memory access at offset {{.*}} overflows this variable31}32