Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add heap corruption testing #87

Merged
merged 3 commits into from
Jun 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Oops
  • Loading branch information
Jake-Shadle committed Jun 8, 2024
commit 191ceaaaca3f5a486f9afeebcc2e1537b274633f
8 changes: 4 additions & 4 deletions sadness-generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ impl SadnessFlavor {
Self::Purecall => raise_purecall(),
#[cfg(windows)]
Self::InvalidParameter => raise_invalid_parameter(),
#[cfg(windows)]
Self::HeapCorruption => raise_heap_corruption(),
#[cfg(target_os = "macos")]
Self::Guard => raise_guard_exception(),
}
Expand Down Expand Up @@ -413,14 +415,12 @@ pub unsafe fn raise_heap_corruption() -> ! {
if kernel32 != 0 {
let heap_free: Option<
unsafe extern "system" fn(HeapHandle, u32, *const core::ffi::c_void) -> Bool,
> = std::mem::transmute(GetProcAddress(kernel32, b"HeapFree\0".as_ptr()));
> = std::mem::transmute(get_proc_address(kernel32, b"HeapFree\0".as_ptr()));

let heap_free = heap_free.expect("failed to acquire HeapFree function");

let heap = GetProcessHeap();
let bad_pointer = 3 as *mut core::ffi::c_void;
heap_free(heap, 0, bad_pointer);
panic!("We should have crashed on the previous line");
heap_free(get_process_heap(), 0, bad_pointer);
} else {
panic!("Can't corrupt heap: failed to load kernel32");
}
Expand Down