From ed9164e47ad2a62fd3f350f8bd5c2518c3a1c784 Mon Sep 17 00:00:00 2001 From: "Takacs, Philipp" Date: Mon, 23 Jan 2023 13:22:55 +0100 Subject: [PATCH] rust only add mmio callback funktion, if callback is requested The C function uc_mmio_map() allows to add seperate callback functions and userdata for read and write. When the callback functions are NULL unicorn don't try to call this functions. Previous this patch, when i.e. read_callback was None the callback was set to mmio_read_callback_proxy and the userdata was set to NULL. On a callback the mmio_read_callback_proxy then tried to dereference the userdata and caused a segfault. fixes #1762 --- bindings/rust/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index 7959e2d5..2aac940d 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -388,12 +388,18 @@ impl<'a, D> Unicorn<'a, D> { self.get_handle(), address, size, - ffi::mmio_read_callback_proxy:: as _, + match read_data { + Some(_) => ffi::mmio_read_callback_proxy:: as _, + None => ptr::null_mut(), + }, match read_data { Some(ref mut d) => d.as_mut() as *mut _ as _, None => ptr::null_mut(), }, - ffi::mmio_write_callback_proxy:: as _, + match write_data { + Some(_) => ffi::mmio_write_callback_proxy:: as _, + None => ptr::null_mut(), + }, match write_data { Some(ref mut d) => d.as_mut() as *mut _ as _, None => ptr::null_mut(),