| 1 | // RUN: %clang_cl_asan %Od %s %Fe%t %MD |
| 2 | // RUN: %env_asan_opts=windows_hook_rtl_allocators=true not %run %t 2>&1 | FileCheck %s |
| 3 | // UNSUPPORTED: asan-64-bits |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <windows.h> |
| 7 | |
| 8 | using AllocateFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, SIZE_T); |
| 9 | using FreeFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, PVOID); |
| 10 | |
| 11 | int main() { |
| 12 | HMODULE NtDllHandle = GetModuleHandle("ntdll.dll" ); |
| 13 | if (!NtDllHandle) { |
| 14 | puts(s: "Couldn't load ntdll??" ); |
| 15 | return -1; |
| 16 | } |
| 17 | |
| 18 | auto RtlAllocateHeap_ptr = (AllocateFunctionPtr)GetProcAddress(NtDllHandle, "RtlAllocateHeap" ); |
| 19 | if (RtlAllocateHeap_ptr == 0) { |
| 20 | puts(s: "Couldn't RtlAllocateHeap" ); |
| 21 | return -1; |
| 22 | } |
| 23 | |
| 24 | char *buffer; |
| 25 | buffer = (char *)RtlAllocateHeap_ptr(GetProcessHeap(), 0, 32), |
| 26 | buffer[33] = 'a'; |
| 27 | // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] |
| 28 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 |
| 29 | } |
| 30 | |