Throw an exception on a failed new in frida ASan, instead of just returning null (#512)

This commit is contained in:
s1341 2022-02-01 16:28:44 +02:00 committed by GitHub
parent fb21c4ff82
commit e41b76fe31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,7 +54,19 @@ impl AsanRuntime {
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[inline] #[inline]
pub fn hook__Znwm(&mut self, size: usize) -> *mut c_void { 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)] #[allow(non_snake_case)]
@ -70,7 +82,17 @@ impl AsanRuntime {
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[inline] #[inline]
pub fn hook__ZnwmSt11align_val_t(&mut self, size: usize, alignment: usize) -> *mut c_void { 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)] #[allow(non_snake_case)]