16a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// RUN: %clang_cl_asan -O0 %s -Fe%t 22d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: not %run %t 2>&1 | FileCheck %s 32d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 42d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#include <stdio.h> 52d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#include <string.h> 62d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 72d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesvoid call_memcpy(void* (*f)(void *, const void *, size_t), 82d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines void *a, const void *b, size_t c) { 92d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines f(a, b, c); 102d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines} 112d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 122d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesint main() { 132d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines char buff1[6] = "Hello", buff2[5]; 142d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 152d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines call_memcpy(&memcpy, buff2, buff1, 5); 162d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines if (buff1[2] != buff2[2]) 172d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines return 2; 182d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines printf("Initial test OK\n"); 192d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines fflush(0); 202d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: Initial test OK 212d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines 222d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines call_memcpy(&memcpy, buff2, buff1, 6); 232d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 242d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: WRITE of size 6 at [[ADDR]] thread T0 2586277eb844c4983c81de62d7c050e92fe7155788Stephen Hines// CHECK-NEXT: __asan_{{.*}}memcpy 262d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK-NEXT: call_memcpy 272d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK-NEXT: main {{.*}}intercept_memcpy.cc:[[@LINE-5]] 282d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame 292d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK-NEXT: #0 {{.*}} main 302d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: 'buff2' <== Memory access at offset {{.*}} overflows this variable 312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines} 32