From ee5ce61995548be80d259df2b9236199c6f5225c Mon Sep 17 00:00:00 2001 From: pankcuf Date: Tue, 12 Sep 2023 22:32:28 +0700 Subject: [PATCH 1/2] fix: check script nullabilty when retrieving an address --- .../src/bindings/address.rs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/dash-spv-masternode-processor/src/bindings/address.rs b/dash-spv-masternode-processor/src/bindings/address.rs index 6cc404d2..cf367597 100644 --- a/dash-spv-masternode-processor/src/bindings/address.rs +++ b/dash-spv-masternode-processor/src/bindings/address.rs @@ -20,19 +20,27 @@ pub extern "C" fn address_from_hash160(hash: *const u8, chain_type: ChainType) - /// # Safety #[no_mangle] pub extern "C" fn address_with_script_pubkey(script: *const u8, script_len: usize, chain_type: ChainType) -> *mut c_char { - let script = unsafe { slice::from_raw_parts(script, script_len) }; - let script_map = chain_type.script_map(); - address::with_script_pub_key(&script.to_vec(), &script_map) - .to_c_string_ptr() + if script.is_null() { + std::ptr::null_mut() + } else { + let script = unsafe { slice::from_raw_parts(script, script_len) }; + let script_map = chain_type.script_map(); + address::with_script_pub_key(&script.to_vec(), &script_map) + .to_c_string_ptr() + } } /// # Safety #[no_mangle] pub extern "C" fn address_with_script_sig(script: *const u8, script_len: usize, chain_type: ChainType) -> *mut c_char { - let script = unsafe { slice::from_raw_parts(script, script_len) }; - let script_map = chain_type.script_map(); - address::with_script_sig(&script.to_vec(), &script_map) - .to_c_string_ptr() + if script.is_null() { + std::ptr::null_mut() + } else { + let script = unsafe { slice::from_raw_parts(script, script_len) }; + let script_map = chain_type.script_map(); + address::with_script_sig(&script.to_vec(), &script_map) + .to_c_string_ptr() + } } /// # Safety From b49e684f3d40f93aa886f28b2eaa4c5ae4775992 Mon Sep 17 00:00:00 2001 From: pankcuf Date: Tue, 12 Sep 2023 22:33:26 +0700 Subject: [PATCH 2/2] chore: bump up bindings version to 0.4.11 --- dash-spv-apple-bindings/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash-spv-apple-bindings/Cargo.toml b/dash-spv-apple-bindings/Cargo.toml index 1c098bed..2bda712a 100644 --- a/dash-spv-apple-bindings/Cargo.toml +++ b/dash-spv-apple-bindings/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dash_spv_apple_bindings" -version = "0.4.10" +version = "0.4.11" description = "C-bindings for using and interoperating with Dash SPV" readme = "README.md" edition = "2021"