Skip to content

Commit e6dd891

Browse files
committed
Fix a use-after-free in the Rust bindings
1 parent c24c9eb commit e6dd891

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

bindings/rust/unicorn-engine/src/hook.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ pub unsafe extern "C" fn code_hook_proxy<D, F>(
6868
) where
6969
F: FnMut(&mut crate::Unicorn<D>, u64, u32),
7070
{
71+
if user_data.is_null() {
72+
return;
73+
}
7174
let user_data = unsafe { &mut *user_data };
7275
let mut user_data_uc = Unicorn {
7376
inner: user_data.uc.upgrade().unwrap(),

uc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,7 @@ uc_err uc_hook_del(uc_engine *uc, uc_hook hh)
20512051
uc);
20522052
g_hash_table_remove_all(hook->hooked_regions);
20532053
hook->to_delete = true;
2054+
hook->user_data = NULL;
20542055
uc->hooks_count[i]--;
20552056
hook_append(&uc->hooks_to_del, hook);
20562057
}

0 commit comments

Comments
 (0)