From e41b76fe3169c8e0a3b2b696463f78db9a7229dc Mon Sep 17 00:00:00 2001 From: s1341 Date: Tue, 1 Feb 2022 16:28:44 +0200 Subject: [PATCH] Throw an exception on a failed new in frida ASan, instead of just returning null (#512) --- libafl_frida/src/asan/hook_funcs.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libafl_frida/src/asan/hook_funcs.rs b/libafl_frida/src/asan/hook_funcs.rs index 80cd03ba63..18cb8904c9 100644 --- a/libafl_frida/src/asan/hook_funcs.rs +++ b/libafl_frida/src/asan/hook_funcs.rs @@ -54,7 +54,19 @@ impl AsanRuntime { #[allow(non_snake_case)] #[inline] pub fn hook__Znwm(&mut self, size: usize) -> *mut c_void { - unsafe { self.allocator_mut().alloc(size, 8) } + let result = unsafe { self.allocator_mut().alloc(size, 8) }; + if result.is_null() { + extern "C" { + fn _ZSt17__throw_bad_allocv(); + } + + unsafe { + _ZSt17__throw_bad_allocv(); + } + 0xabcdef as *mut c_void + } else { + result + } } #[allow(non_snake_case)] @@ -70,7 +82,17 @@ impl AsanRuntime { #[allow(non_snake_case)] #[inline] pub fn hook__ZnwmSt11align_val_t(&mut self, size: usize, alignment: usize) -> *mut c_void { - unsafe { self.allocator_mut().alloc(size, alignment) } + let result = unsafe { self.allocator_mut().alloc(size, alignment) }; + if result.is_null() { + extern "C" { + fn _ZSt17__throw_bad_allocv(); + } + + unsafe { + _ZSt17__throw_bad_allocv(); + } + } + result } #[allow(non_snake_case)]