Files
TransPyC/heapvalidate_test.c

34 lines
845 B
C

#include <malloc.h>
#include <stdio.h>
#include <windows.h>
int main() {
HANDLE h = GetProcessHeap();
printf("process heap handle: %p\n", h);
fflush(stdout);
/* validate before any alloc */
BOOL v0 = HeapValidate(h, 0, NULL);
printf("before alloc: HeapValidate=%d\n", v0);
fflush(stdout);
void *p = malloc(1024);
BOOL v1 = HeapValidate(h, 0, NULL);
printf("after malloc(1024): HeapValidate=%d (p=%p)\n", v1, p);
fflush(stdout);
/* intentionally overflow */
memset((char*)p + 1024, 0xCC, 64);
BOOL v2 = HeapValidate(h, 0, NULL);
printf("after overflow: HeapValidate=%d\n", v2);
fflush(stdout);
/* try to trigger detection via free */
free(p);
BOOL v3 = HeapValidate(h, 0, NULL);
printf("after free: HeapValidate=%d\n", v3);
fflush(stdout);
return 0;
}