From 298b7453c2ef7446515094e9935487e1431f56a1 Mon Sep 17 00:00:00 2001 From: ahgamut <41098605+ahgamut@users.noreply.github.com> Date: Sun, 26 Jun 2022 21:07:19 +0530 Subject: [PATCH] example to trigger Cosmopolitan's ASAN runtime --- src/bin/unsafe-but-asan.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/unsafe-but-asan.rs diff --git a/src/bin/unsafe-but-asan.rs b/src/bin/unsafe-but-asan.rs new file mode 100644 index 0000000..39945fa --- /dev/null +++ b/src/bin/unsafe-but-asan.rs @@ -0,0 +1,27 @@ +#![no_main] +#![no_std] +#![feature(rustc_private)] + +extern crate libc; + +extern "C" { + fn ShowCrashReports(); +} + +#[no_mangle] +pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize { + unsafe { + ShowCrashReports(); + let mut buffer = libc::malloc(13); + const c_str: &'static str = "Hello\0"; + libc::strcpy(buffer as *mut i8, c_str.as_ptr() as *const i8); + libc::free(buffer); + libc::printf(buffer as *const _); + } + 0 +} + +#[panic_handler] +fn my_panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +}