brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 4fa4379 Raw
35 lines · cpp
1// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t2// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} %LD %Od %s %Fe%t.dll3// RUN: not %run %t %t.dll 2>&1 | FileCheck %s4 5// Test that it works correctly even with ICF enabled.6// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} %LD %Od %s %Fe%t.dll \7// RUN:   %if target={{.*-windows-gnu}} %{ -Wl,--gc-sections,--icf=all %} \8// RUN:   %else %{ -link /OPT:REF /OPT:ICF %}9// RUN: not %run %t %t.dll 2>&1 | FileCheck %s10 11#include <stdio.h>12#include <string.h>13 14extern "C" __declspec(dllexport)15int test_function() {16  char buff1[6] = "Hello", buff2[5];17 18  memcpy(buff2, buff1, 5);19  if (buff1[2] != buff2[2])20    return 2;21  printf("Initial test OK\n");22  fflush(0);23// CHECK: Initial test OK24 25  memcpy(buff2, buff1, 6);26  // CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]27  // CHECK: WRITE of size 6 at [[ADDR]] thread T028  // CHECK-NEXT:  __asan_{{.*}}{{(memcpy|memmove)}}29  // CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy.cpp:[[@LINE-4]]30  // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame31  // CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy.cpp32  // CHECK: 'buff2'{{.*}} <== Memory access at offset {{.*}} overflows this variable33  return 0;34}35