]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
rust: remove all usage of transmute
authorJason Ish <jason.ish@oisf.net>
Mon, 26 Jul 2021 19:25:17 +0000 (13:25 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 23 Aug 2021 08:03:12 +0000 (10:03 +0200)
All cases of our transmute can be replaced with more idiomatic
solutions and do no require the power of transmute.

When returning an object to C for life-time management, use
Box::into_raw to convert the boxed object to pointer and use
Box::from_raw to convert back.

For cases where we're just returning a pointer to Rust managed
data, use a cast.

22 files changed:
rust/src/applayertemplate/template.rs
rust/src/dcerpc/dcerpc.rs
rust/src/dcerpc/dcerpc_udp.rs
rust/src/dcerpc/detect.rs
rust/src/dhcp/dhcp.rs
rust/src/dhcp/logger.rs
rust/src/dns/detect.rs
rust/src/dns/dns.rs
rust/src/http2/detect.rs
rust/src/http2/http2.rs
rust/src/ike/ike.rs
rust/src/krb/krb5.rs
rust/src/mqtt/mqtt.rs
rust/src/nfs/nfs.rs
rust/src/ntp/ntp.rs
rust/src/rdp/rdp.rs
rust/src/rfb/rfb.rs
rust/src/sip/sip.rs
rust/src/smb/smb.rs
rust/src/snmp/snmp.rs
rust/src/ssh/ssh.rs
rust/src/tftp/tftp.rs

index 50af3526eab3e0d148f7e664cb4f781d04a26ab3..36f6d3b79055123e8e94003b066f0395403dcb75 100644 (file)
@@ -17,7 +17,6 @@
 
 use std;
 use crate::core::{self, ALPROTO_UNKNOWN, AppProto, Flow, IPPROTO_TCP};
-use std::mem::transmute;
 use crate::applayer::{self, *};
 use std::ffi::CString;
 use nom;
@@ -298,13 +297,12 @@ pub extern "C" fn rs_template_probing_parser(
 pub extern "C" fn rs_template_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = TemplateState::new();
     let boxed = Box::new(state);
-    return unsafe { transmute(boxed) };
+    return Box::into_raw(boxed) as *mut std::os::raw::c_void;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_template_state_free(state: *mut std::os::raw::c_void) {
-    // Just unbox...
-    let _drop: Box<TemplateState> = unsafe { transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut TemplateState) });
 }
 
 #[no_mangle]
@@ -390,7 +388,7 @@ pub extern "C" fn rs_template_state_get_tx(
     let state = cast_pointer!(state, TemplateState);
     match state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe { transmute(tx) };
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -456,7 +454,7 @@ pub extern "C" fn rs_template_state_get_tx_iterator(
     let state = cast_pointer!(state, TemplateState);
     match state.tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(
                 c_tx,
                 out_tx_id,
index 51743c8cc90184d17eaef40c56a4681980e0e22c..d7b54f0f7522456dc0032b7fe7555a0cc3d9d2dd 100644 (file)
@@ -15,7 +15,6 @@
  * 02110-1301, USA.
  */
 
-use std::mem::transmute;
 use crate::applayer::*;
 use crate::core::{self, *};
 use crate::dcerpc::parser;
@@ -1193,12 +1192,12 @@ pub extern "C" fn rs_dcerpc_parse_response(
 pub extern "C" fn rs_dcerpc_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: core::AppProto) -> *mut std::os::raw::c_void {
     let state = DCERPCState::new();
     let boxed = Box::new(state);
-    return unsafe { transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_dcerpc_state_free(state: *mut std::os::raw::c_void) {
-    let _state: Box<DCERPCState> = unsafe { transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut DCERPCState)} );
 }
 
 #[no_mangle]
@@ -1258,7 +1257,7 @@ pub extern "C" fn rs_dcerpc_get_tx(
 ) -> *mut std::os::raw::c_void {
     let dce_state = cast_pointer!(vtx, DCERPCState);
     match dce_state.get_tx(tx_id) {
-        Some(tx) => unsafe { transmute(tx) },
+        Some(tx) => tx as *const _ as *mut _,
         None => std::ptr::null_mut(),
     }
 }
index c3671aaccb5ff883efce3fbdcd01da18f9bb48ba..f6f5ed961f7a8355a4baf87643a143b7c86c2752 100644 (file)
@@ -15,8 +15,6 @@
  * 02110-1301, USA.
  */
 
-use std::mem::transmute;
-
 use crate::applayer::*;
 use crate::core;
 use crate::dcerpc::dcerpc::{
@@ -221,14 +219,14 @@ pub extern "C" fn rs_dcerpc_udp_parse(
 
 #[no_mangle]
 pub extern "C" fn rs_dcerpc_udp_state_free(state: *mut std::os::raw::c_void) {
-    let _drop: Box<DCERPCUDPState> = unsafe { transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut DCERPCUDPState) });
 }
 
 #[no_mangle]
 pub extern "C" fn rs_dcerpc_udp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: core::AppProto) -> *mut std::os::raw::c_void {
     let state = DCERPCUDPState::new();
     let boxed = Box::new(state);
-    return unsafe { transmute(boxed) };
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
@@ -276,7 +274,7 @@ pub extern "C" fn rs_dcerpc_udp_get_tx(
     let dce_state = cast_pointer!(state, DCERPCUDPState);
     match dce_state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe{ transmute(tx) };
+            return tx as *const _ as *mut _;
         },
         None => {
             return std::ptr::null_mut();
index 49b3492c6c6b06d593c01e1a43c4b4a9bc4593a5..5be74782a6c12507fd950c6f0a046d0cf8fb92d3 100644 (file)
@@ -281,7 +281,7 @@ pub unsafe extern "C" fn rs_dcerpc_iface_parse(carg: *const c_char) -> *mut c_vo
     };
 
     match parse_iface_data(&arg) {
-        Ok(detect) => std::mem::transmute(Box::new(detect)),
+        Ok(detect) => Box::into_raw(Box::new(detect)) as *mut _,
         Err(_) => std::ptr::null_mut(),
     }
 }
@@ -289,7 +289,7 @@ pub unsafe extern "C" fn rs_dcerpc_iface_parse(carg: *const c_char) -> *mut c_vo
 #[no_mangle]
 pub unsafe extern "C" fn rs_dcerpc_iface_free(ptr: *mut c_void) {
     if ptr != std::ptr::null_mut() {
-        let _: Box<DCEIfaceData> = std::mem::transmute(ptr);
+        std::mem::drop(Box::from_raw(ptr as *mut DCEIfaceData));
     }
 }
 
@@ -328,7 +328,7 @@ pub unsafe extern "C" fn rs_dcerpc_opnum_parse(carg: *const c_char) -> *mut c_vo
     };
 
     match parse_opnum_data(&arg) {
-        Ok(detect) => std::mem::transmute(Box::new(detect)),
+        Ok(detect) => Box::into_raw(Box::new(detect)) as *mut _,
         Err(_) => std::ptr::null_mut(),
     }
 }
@@ -336,7 +336,7 @@ pub unsafe extern "C" fn rs_dcerpc_opnum_parse(carg: *const c_char) -> *mut c_vo
 #[no_mangle]
 pub unsafe extern "C" fn rs_dcerpc_opnum_free(ptr: *mut c_void) {
     if ptr != std::ptr::null_mut() {
-        let _: Box<DCEOpnumData> = std::mem::transmute(ptr);
+        std::mem::drop(Box::from_raw(ptr as *mut DCEOpnumData));
     }
 }
 
index d90a281eb10f65cae10047a166a254a3e8df6ef8..a9ae1f42c2e1caa26e3e24680651d89981e5af7c 100644 (file)
@@ -22,7 +22,6 @@ use crate::core::{sc_detect_engine_state_free, sc_app_layer_decoder_events_free_
 use crate::dhcp::parser::*;
 use std;
 use std::ffi::{CStr,CString};
-use std::mem::transmute;
 
 static mut ALPROTO_DHCP: AppProto = ALPROTO_UNKNOWN;
 
@@ -256,7 +255,7 @@ pub extern "C" fn rs_dhcp_state_get_tx(state: *mut std::os::raw::c_void,
     let state = cast_pointer!(state, DHCPState);
     match state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe { transmute(tx) };
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -299,15 +298,12 @@ pub extern "C" fn rs_dhcp_state_tx_free(
 pub extern "C" fn rs_dhcp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = DHCPState::new();
     let boxed = Box::new(state);
-    return unsafe {
-        transmute(boxed)
-    };
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_dhcp_state_free(state: *mut std::os::raw::c_void) {
-    // Just unbox...
-    let _drop: Box<DHCPState> = unsafe { transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut DHCPState) });
 }
 
 #[no_mangle]
@@ -379,7 +375,7 @@ pub extern "C" fn rs_dhcp_state_get_tx_iterator(
     let state = cast_pointer!(state, DHCPState);
     match state.get_tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(
                 c_tx, out_tx_id, has_next);
             return ires;
index 135d523278c16e3e1b0f3951ed85cbf9e303f1ef..1b4b4a977c55be6da5d7d8e2d77844380bb5edbf 100644 (file)
@@ -259,12 +259,12 @@ fn format_addr_hex(input: &Vec<u8>) -> String {
 pub extern "C" fn rs_dhcp_logger_new(conf: *const c_void) -> *mut std::os::raw::c_void {
     let conf = ConfNode::wrap(conf);
     let boxed = Box::new(DHCPLogger::new(conf));
-    return unsafe{std::mem::transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_dhcp_logger_free(logger: *mut std::os::raw::c_void) {
-    let _: Box<DHCPLogger> = unsafe{std::mem::transmute(logger)};
+    std::mem::drop(unsafe { Box::from_raw(logger as *mut DHCPLogger) });
 }
 
 #[no_mangle]
index bbf3c71c75223d573fb627407c645483a85ab37f..3cf626e0172dc9cec9ba3f88a78761946a7f92b4 100644 (file)
@@ -108,7 +108,7 @@ pub unsafe extern "C" fn rs_detect_dns_opcode_parse(carg: *const c_char) -> *mut
     };
 
     match parse_opcode(&arg) {
-        Ok(detect) => std::mem::transmute(Box::new(detect)),
+        Ok(detect) => Box::into_raw(Box::new(detect)) as *mut _,
         Err(_) => std::ptr::null_mut(),
     }
 }
@@ -116,7 +116,7 @@ pub unsafe extern "C" fn rs_detect_dns_opcode_parse(carg: *const c_char) -> *mut
 #[no_mangle]
 pub unsafe extern "C" fn rs_dns_detect_opcode_free(ptr: *mut c_void) {
     if ptr != std::ptr::null_mut() {
-        let _: Box<DetectDnsOpcode> = std::mem::transmute(ptr);
+        std::mem::drop(Box::from_raw(ptr as *mut DetectDnsOpcode));
     }
 }
 
index e0f0f8a9c36e0dc5c36e983af721f84ea2bc3202..76c441d4997eddee03ba68ed0398db0ad670cafa 100644 (file)
@@ -19,7 +19,6 @@ extern crate nom;
 
 use std;
 use std::ffi::CString;
-use std::mem::transmute;
 use std::collections::HashMap;
 use std::collections::VecDeque;
 
@@ -720,7 +719,7 @@ pub fn probe_tcp(input: &[u8]) -> (bool, bool, bool) {
 pub extern "C" fn rs_dns_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = DNSState::new();
     let boxed = Box::new(state);
-    return unsafe{transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 /// Returns *mut DNSState
@@ -728,7 +727,7 @@ pub extern "C" fn rs_dns_state_new(_orig_state: *mut std::os::raw::c_void, _orig
 pub extern "C" fn rs_dns_state_tcp_new() -> *mut std::os::raw::c_void {
     let state = DNSState::new_tcp();
     let boxed = Box::new(state);
-    return unsafe{transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 /// Params:
@@ -736,7 +735,7 @@ pub extern "C" fn rs_dns_state_tcp_new() -> *mut std::os::raw::c_void {
 #[no_mangle]
 pub extern "C" fn rs_dns_state_free(state: *mut std::os::raw::c_void) {
     // Just unbox...
-    let _drop: Box<DNSState> = unsafe{transmute(state)};
+    std::mem::drop(unsafe { Box::from_raw(state as *mut DNSState) });
 }
 
 #[no_mangle]
@@ -855,7 +854,7 @@ pub extern "C" fn rs_dns_state_get_tx(state: *mut std::os::raw::c_void,
     let state = cast_pointer!(state, DNSState);
     match state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe{transmute(tx)};
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
index 40f4ec7e71bd388e2db64cc04bba45058cf82e07..3248b897cbf6664d6244d48f4dcc89438cd7db6c 100644 (file)
@@ -21,7 +21,6 @@ use super::http2::{
 use super::parser;
 use crate::core::STREAM_TOSERVER;
 use std::ffi::CStr;
-use std::mem::transmute;
 use std::str::FromStr;
 
 fn http2_tx_has_frametype(
@@ -234,7 +233,7 @@ pub unsafe extern "C" fn rs_http2_detect_settingsctx_parse(
     if let Ok(s) = ft_name.to_str() {
         if let Ok((_, ctx)) = parser::http2_parse_settingsctx(s) {
             let boxed = Box::new(ctx);
-            return transmute(boxed); //unsafe
+            return Box::into_raw(boxed) as *mut _;
         }
     }
     return std::ptr::null_mut();
@@ -243,7 +242,7 @@ pub unsafe extern "C" fn rs_http2_detect_settingsctx_parse(
 #[no_mangle]
 pub unsafe extern "C" fn rs_http2_detect_settingsctx_free(ctx: *mut std::os::raw::c_void) {
     // Just unbox...
-    let _ctx: Box<parser::DetectHTTP2settingsSigCtx> = transmute(ctx);
+    std::mem::drop(Box::from_raw(ctx as *mut parser::DetectHTTP2settingsSigCtx));
 }
 
 fn http2_detect_settings_match(
@@ -329,7 +328,7 @@ pub unsafe extern "C" fn rs_detect_u64_parse(
     if let Ok(s) = ft_name.to_str() {
         if let Ok((_, ctx)) = parser::detect_parse_u64(s) {
             let boxed = Box::new(ctx);
-            return transmute(boxed); //unsafe
+            return Box::into_raw(boxed) as *mut _;
         }
     }
     return std::ptr::null_mut();
@@ -338,7 +337,7 @@ pub unsafe extern "C" fn rs_detect_u64_parse(
 #[no_mangle]
 pub unsafe extern "C" fn rs_detect_u64_free(ctx: *mut std::os::raw::c_void) {
     // Just unbox...
-    let _ctx: Box<parser::DetectU64Data> = transmute(ctx);
+    std::mem::drop(Box::from_raw(ctx as *mut parser::DetectU64Data));
 }
 
 fn http2_detect_sizeupdate_match(
index efa1802e1a2a7b62fdb7f8a37b332051034ded92..c11e9d3ec64e9943152fdd36453cd1ca2c65c6bf 100644 (file)
@@ -29,7 +29,6 @@ use std;
 use std::ffi::{CStr, CString};
 use std::fmt;
 use std::io;
-use std::mem::transmute;
 
 static mut ALPROTO_HTTP2: AppProto = ALPROTO_UNKNOWN;
 
@@ -1004,7 +1003,7 @@ pub extern "C" fn rs_http2_state_new(
 ) -> *mut std::os::raw::c_void {
     let state = HTTP2State::new();
     let boxed = Box::new(state);
-    let r = unsafe { transmute(boxed) };
+    let r = Box::into_raw(boxed) as *mut _;
     if orig_state != std::ptr::null_mut() {
         //we could check ALPROTO_HTTP1 == orig_proto
         unsafe {
@@ -1016,8 +1015,7 @@ pub extern "C" fn rs_http2_state_new(
 
 #[no_mangle]
 pub extern "C" fn rs_http2_state_free(state: *mut std::os::raw::c_void) {
-    // Just unbox...
-    let mut state: Box<HTTP2State> = unsafe { transmute(state) };
+    let mut state: Box<HTTP2State> = unsafe { Box::from_raw(state as _) };
     state.free();
 }
 
@@ -1059,7 +1057,7 @@ pub extern "C" fn rs_http2_state_get_tx(
     let state = cast_pointer!(state, HTTP2State);
     match state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe { transmute(tx) };
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -1163,7 +1161,7 @@ pub extern "C" fn rs_http2_state_get_tx_iterator(
     let state = cast_pointer!(state, HTTP2State);
     match state.tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(c_tx, out_tx_id, has_next);
             return ires;
         }
index bcd6ffcec6d6819f05556f668aad820091c69883..0a9b4fc07d99c0cad2691c7a058dd6f4808bed3c 100644 (file)
@@ -32,7 +32,6 @@ use nom;
 use std;
 use std::collections::HashSet;
 use std::ffi::{CStr, CString};
-use std::mem::transmute;
 
 #[repr(u32)]
 pub enum IkeEvent {
@@ -346,13 +345,13 @@ pub extern "C" fn rs_ike_state_new(
 ) -> *mut std::os::raw::c_void {
     let state = IKEState::default();
     let boxed = Box::new(state);
-    return unsafe { transmute(boxed) };
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_ike_state_free(state: *mut std::os::raw::c_void) {
     // Just unbox...
-    let _drop: Box<IKEState> = unsafe { transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut IKEState) });
 }
 
 #[no_mangle]
@@ -389,7 +388,7 @@ pub extern "C" fn rs_ike_state_get_tx(
     let state = cast_pointer!(state, IKEState);
     match state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe { transmute(tx) };
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -516,7 +515,7 @@ pub extern "C" fn rs_ike_state_get_tx_iterator(
     let state = cast_pointer!(state, IKEState);
     match state.tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(c_tx, out_tx_id, has_next);
             return ires;
         }
index 389bbc7b3cdca60066a3d32f13a0d3cb8eb03918..564266c0f815cf7c184b24554f4eeabe2d5ee4c7 100644 (file)
@@ -276,15 +276,14 @@ pub fn test_weak_encryption(alg:EncryptionType) -> bool {
 pub extern "C" fn rs_krb5_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = KRB5State::new();
     let boxed = Box::new(state);
-    return unsafe{std::mem::transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 /// Params:
 /// - state: *mut KRB5State as void pointer
 #[no_mangle]
 pub extern "C" fn rs_krb5_state_free(state: *mut std::os::raw::c_void) {
-    // Just unbox...
-    let mut state: Box<KRB5State> = unsafe{std::mem::transmute(state)};
+    let mut state: Box<KRB5State> = unsafe{Box::from_raw(state as _)};
     state.free();
 }
 
@@ -295,7 +294,7 @@ pub extern "C" fn rs_krb5_state_get_tx(state: *mut std::os::raw::c_void,
 {
     let state = cast_pointer!(state,KRB5State);
     match state.get_tx_by_id(tx_id) {
-        Some(tx) => unsafe{std::mem::transmute(tx)},
+        Some(tx) => tx as *const _ as *mut _,
         None     => std::ptr::null_mut(),
     }
 }
index fab018eda2005cc8c904135c4ae1c351c01fb29c..1ced80ee34d9f7ec9b31a9c8bd127e9578ef9683 100644 (file)
@@ -26,7 +26,6 @@ use num_traits::FromPrimitive;
 use nom;
 use std;
 use std::ffi::{CStr,CString};
-use std::mem::transmute;
 
 // Used as a special pseudo packet identifier to denote the first CONNECT
 // packet in a connection. Note that there is no risk of collision with a
@@ -581,12 +580,12 @@ pub extern "C" fn rs_mqtt_probing_parser(
 pub extern "C" fn rs_mqtt_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = MQTTState::new();
     let boxed = Box::new(state);
-    return unsafe { transmute(boxed) };
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_mqtt_state_free(state: *mut std::os::raw::c_void) {
-    let _drop: Box<MQTTState> = unsafe { transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut MQTTState) });
 }
 
 #[no_mangle]
@@ -633,7 +632,7 @@ pub extern "C" fn rs_mqtt_state_get_tx(
     let state = cast_pointer!(state, MQTTState);
     match state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe { transmute(tx) };
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -775,7 +774,7 @@ pub extern "C" fn rs_mqtt_state_get_tx_iterator(
     let state = cast_pointer!(state, MQTTState);
     match state.tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(c_tx, out_tx_id, has_next);
             return ires;
         }
index 969ed29185a047a0e82367090bd192bb705e1046..2c3f18f7c226fde5336f477f22efb962e524010e 100644 (file)
@@ -19,7 +19,6 @@
 
 use std;
 use std::cmp;
-use std::mem::transmute;
 use std::collections::{HashMap};
 use std::ffi::{CStr, CString};
 
@@ -1377,7 +1376,7 @@ pub extern "C" fn rs_nfs_state_new(_orig_state: *mut std::os::raw::c_void, _orig
     let state = NFSState::new();
     let boxed = Box::new(state);
     SCLogDebug!("allocating state");
-    return unsafe{transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 /// Params:
@@ -1386,7 +1385,7 @@ pub extern "C" fn rs_nfs_state_new(_orig_state: *mut std::os::raw::c_void, _orig
 pub extern "C" fn rs_nfs_state_free(state: *mut std::os::raw::c_void) {
     // Just unbox...
     SCLogDebug!("freeing state");
-    let mut _nfs_state: Box<NFSState> = unsafe{transmute(state)};
+    std::mem::drop(unsafe { Box::from_raw(state as *mut NFSState) });
 }
 
 /// C binding parse a NFS TCP request. Returns 1 on success, -1 on failure.
@@ -1511,7 +1510,7 @@ pub extern "C" fn rs_nfs_state_get_tx(state: *mut std::os::raw::c_void,
     let state = cast_pointer!(state, NFSState);
     match state.get_tx_by_id(tx_id) {
         Some(tx) => {
-            return unsafe{transmute(tx)};
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -1533,7 +1532,7 @@ pub extern "C" fn rs_nfs_state_get_tx_iterator(
     let state = cast_pointer!(state, NFSState);
     match state.get_tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(c_tx, out_tx_id, has_next);
             return ires;
         }
index 02e9fdca9bf60f833e70b2365fcc1b92bd7a4322..7d6ce269d1f4140fe447e073d22d9d7dbf5adf69 100644 (file)
@@ -178,15 +178,14 @@ impl Drop for NTPTransaction {
 pub extern "C" fn rs_ntp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = NTPState::new();
     let boxed = Box::new(state);
-    return unsafe{std::mem::transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 /// Params:
 /// - state: *mut NTPState as void pointer
 #[no_mangle]
 pub extern "C" fn rs_ntp_state_free(state: *mut std::os::raw::c_void) {
-    // Just unbox...
-    let mut ntp_state: Box<NTPState> = unsafe{std::mem::transmute(state)};
+    let mut ntp_state = unsafe{ Box::from_raw(state as *mut NTPState) };
     ntp_state.free();
 }
 
@@ -229,7 +228,7 @@ pub extern "C" fn rs_ntp_state_get_tx(state: *mut std::os::raw::c_void,
 {
     let state = cast_pointer!(state,NTPState);
     match state.get_tx_by_id(tx_id) {
-        Some(tx) => unsafe{std::mem::transmute(tx)},
+        Some(tx) => tx as *const _ as *mut _,
         None     => std::ptr::null_mut(),
     }
 }
index 55f2ddd3ecf5a0c4cc841d5d7bdbc79bc3c8d915..6f578189fec3af75e8bceb54433675de2626fbcc 100644 (file)
@@ -24,7 +24,6 @@ use crate::core::{self, AppProto, DetectEngineState, Flow, ALPROTO_UNKNOWN, IPPR
 use crate::rdp::parser::*;
 use nom;
 use std;
-use std::mem::transmute;
 use tls_parser::{parse_tls_plaintext, TlsMessage, TlsMessageHandshake, TlsRecordType};
 
 static mut ALPROTO_RDP: AppProto = ALPROTO_UNKNOWN;
@@ -86,7 +85,7 @@ pub extern "C" fn rs_rdp_state_get_tx(
     let state = cast_pointer!(state, RdpState);
     match state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe { transmute(tx) };
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -376,12 +375,12 @@ impl RdpState {
 pub extern "C" fn rs_rdp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = RdpState::new();
     let boxed = Box::new(state);
-    return unsafe { std::mem::transmute(boxed) };
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_rdp_state_free(state: *mut std::os::raw::c_void) {
-    let _drop: Box<RdpState> = unsafe { std::mem::transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut RdpState) });
 }
 
 #[no_mangle]
index 3bbc330551450ee0a7a426770dc1a01932db9746..1b0c5019da5368646e5ad699e8739898e427c7d4 100644 (file)
@@ -19,7 +19,6 @@
 
 use std;
 use std::ffi::CString;
-use std::mem::transmute;
 use crate::core::{self, ALPROTO_UNKNOWN, AppProto, Flow, IPPROTO_TCP};
 use crate::applayer;
 use crate::applayer::*;
@@ -521,13 +520,13 @@ export_tx_set_detect_state!(
 pub extern "C" fn rs_rfb_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = RFBState::new();
     let boxed = Box::new(state);
-    return unsafe { transmute(boxed) };
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_rfb_state_free(state: *mut std::os::raw::c_void) {
     // Just unbox...
-    let _drop: Box<RFBState> = unsafe { transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut RFBState) });
 }
 
 #[no_mangle]
@@ -577,7 +576,7 @@ pub extern "C" fn rs_rfb_state_get_tx(
     let state = cast_pointer!(state, RFBState);
     match state.get_tx(tx_id) {
         Some(tx) => {
-            return unsafe { transmute(tx) };
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -641,7 +640,7 @@ pub extern "C" fn rs_rfb_state_get_tx_iterator(
     let state = cast_pointer!(state, RFBState);
     match state.tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(
                 c_tx,
                 out_tx_id,
index 8874bdccef8ec4b28c9f003f4823c2d9c14fd93a..4cc8bf8e21b6b2f68bb774dda30f821bee6af40d 100755 (executable)
@@ -172,12 +172,12 @@ impl Drop for SIPTransaction {
 pub extern "C" fn rs_sip_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = SIPState::new();
     let boxed = Box::new(state);
-    return unsafe { std::mem::transmute(boxed) };
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_sip_state_free(state: *mut std::os::raw::c_void) {
-    let mut state: Box<SIPState> = unsafe { std::mem::transmute(state) };
+    let mut state = unsafe { Box::from_raw(state as *mut SIPState) };
     state.free();
 }
 
@@ -188,7 +188,7 @@ pub extern "C" fn rs_sip_state_get_tx(
 ) -> *mut std::os::raw::c_void {
     let state = cast_pointer!(state, SIPState);
     match state.get_tx_by_id(tx_id) {
-        Some(tx) => unsafe { std::mem::transmute(tx) },
+        Some(tx) => tx as *const _ as *mut _,
         None => std::ptr::null_mut(),
     }
 }
index 4a0ff9adc84f7ac8d360ac08d0bd718b31840ff7..f2f091b616ff1839568748dcc0232857006e9518 100644 (file)
@@ -26,7 +26,6 @@
 // written by Victor Julien
 
 use std;
-use std::mem::transmute;
 use std::str;
 use std::ffi::{self, CStr, CString};
 
@@ -1798,16 +1797,15 @@ pub extern "C" fn rs_smb_state_new(_orig_state: *mut std::os::raw::c_void, _orig
     let state = SMBState::new();
     let boxed = Box::new(state);
     SCLogDebug!("allocating state");
-    return unsafe{transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 /// Params:
 /// - state: *mut SMBState as void pointer
 #[no_mangle]
 pub extern "C" fn rs_smb_state_free(state: *mut std::os::raw::c_void) {
-    // Just unbox...
     SCLogDebug!("freeing state");
-    let mut smb_state: Box<SMBState> = unsafe{transmute(state)};
+    let mut smb_state = unsafe { Box::from_raw(state as *mut SMBState) };
     smb_state.free();
 }
 
@@ -2021,7 +2019,7 @@ pub extern "C" fn rs_smb_state_get_tx(state: *mut ffi::c_void,
     let state = cast_pointer!(state, SMBState);
     match state.get_tx_by_id(tx_id) {
         Some(tx) => {
-            return unsafe{transmute(tx)};
+            return tx as *const _ as *mut _;
         }
         None => {
             return std::ptr::null_mut();
@@ -2043,7 +2041,7 @@ pub extern "C" fn rs_smb_state_get_tx_iterator(
     let state = cast_pointer!(state, SMBState);
     match state.get_tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(c_tx, out_tx_id, has_next);
             return ires;
         }
index 88715ccb8122098db525694b5ec7cb12d99d776c..3ad187593f05afe61621b9286a09410e6265f83d 100644 (file)
@@ -23,7 +23,6 @@ use crate::core::{AppProto,Flow,ALPROTO_UNKNOWN,ALPROTO_FAILED,STREAM_TOSERVER,S
 use crate::applayer::{self, *};
 use std;
 use std::ffi::{CStr,CString};
-use std::mem::transmute;
 
 use der_parser::ber::BerObjectContent;
 use der_parser::der::parse_der_sequence;
@@ -300,15 +299,14 @@ impl<'a> Drop for SNMPTransaction<'a> {
 pub extern "C" fn rs_snmp_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = SNMPState::new();
     let boxed = Box::new(state);
-    return unsafe{std::mem::transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 /// Params:
 /// - state: *mut SNMPState as void pointer
 #[no_mangle]
 pub extern "C" fn rs_snmp_state_free(state: *mut std::os::raw::c_void) {
-    // Just unbox...
-    let mut snmp_state: Box<SNMPState> = unsafe{std::mem::transmute(state)};
+    let mut snmp_state = unsafe{ Box::from_raw(state as *mut SNMPState) };
     snmp_state.free();
 }
 
@@ -345,7 +343,7 @@ pub extern "C" fn rs_snmp_state_get_tx(state: *mut std::os::raw::c_void,
 {
     let state = cast_pointer!(state,SNMPState);
     match state.get_tx_by_id(tx_id) {
-        Some(tx) => unsafe{std::mem::transmute(tx)},
+        Some(tx) => tx as *const _ as *mut _,
         None     => std::ptr::null_mut(),
     }
 }
@@ -463,7 +461,7 @@ pub extern "C" fn rs_snmp_state_get_tx_iterator(
 {
     match state.get_tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(c_tx, out_tx_id, has_next);
             return ires;
         }
@@ -485,7 +483,7 @@ pub extern "C" fn rs_snmp_get_tx_iterator(_ipproto: u8,
     let state = cast_pointer!(alstate,SNMPState);
     match state.get_tx_iterator(min_tx_id, istate) {
         Some((tx, out_tx_id, has_next)) => {
-            let c_tx = unsafe { transmute(tx) };
+            let c_tx = tx as *const _ as *mut _;
             let ires = applayer::AppLayerGetTxIterTuple::with_values(c_tx, out_tx_id, has_next);
             return ires;
         }
index 196e18e7e517cc3bc55cb914b859accd47a35502..d79f9860f61fc529dbbc73ccb1f98df081c2b742 100644 (file)
@@ -20,7 +20,6 @@ use crate::applayer::*;
 use crate::core::STREAM_TOSERVER;
 use crate::core::{self, AppProto, Flow, ALPROTO_UNKNOWN, IPPROTO_TCP};
 use std::ffi::{CStr, CString};
-use std::mem::transmute;
 use std::sync::atomic::{AtomicBool, Ordering};
 
 static mut ALPROTO_SSH: AppProto = ALPROTO_UNKNOWN;
@@ -431,13 +430,12 @@ pub extern "C" fn rs_ssh_state_get_event_info_by_id(
 pub extern "C" fn rs_ssh_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
     let state = SSHState::new();
     let boxed = Box::new(state);
-    return unsafe { transmute(boxed) };
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_ssh_state_free(state: *mut std::os::raw::c_void) {
-    // Just unbox...
-    let _drop: Box<SSHState> = unsafe { transmute(state) };
+    std::mem::drop(unsafe { Box::from_raw(state as *mut SSHState) });
 }
 
 #[no_mangle]
@@ -480,7 +478,7 @@ pub extern "C" fn rs_ssh_state_get_tx(
     state: *mut std::os::raw::c_void, _tx_id: u64,
 ) -> *mut std::os::raw::c_void {
     let state = cast_pointer!(state, SSHState);
-    return unsafe { transmute(&state.transaction) };
+    return &state.transaction as *const _ as *mut _;
 }
 
 #[no_mangle]
index 361c8e15cbc81e57b4918b5aa400838812172d8a..977f95c7b4bb72f50b5dbc9e4bf1fdde8c632851 100644 (file)
@@ -21,7 +21,6 @@ extern crate nom;
 
 use std::str;
 use std;
-use std::mem::transmute;
 use nom::*;
 
 use crate::applayer::AppLayerTxData;
@@ -89,12 +88,12 @@ impl TFTPTransaction {
 pub extern "C" fn rs_tftp_state_alloc() -> *mut std::os::raw::c_void {
     let state = TFTPState { transactions : Vec::new(), tx_id: 0, };
     let boxed = Box::new(state);
-    return unsafe{transmute(boxed)};
+    return Box::into_raw(boxed) as *mut _;
 }
 
 #[no_mangle]
 pub extern "C" fn rs_tftp_state_free(state: *mut std::os::raw::c_void) {
-    let _state : Box<TFTPState> = unsafe{transmute(state)};
+    std::mem::drop(unsafe { Box::from_raw(state as *mut TFTPState) });
 }
 
 #[no_mangle]
@@ -107,7 +106,7 @@ pub extern "C" fn rs_tftp_state_tx_free(state: &mut TFTPState,
 pub extern "C" fn rs_tftp_get_tx(state: &mut TFTPState,
                                     tx_id: u64) -> *mut std::os::raw::c_void {
     match state.get_tx_by_id(tx_id) {
-        Some(tx) => unsafe{std::mem::transmute(tx)},
+        Some(tx) => tx as *const _ as *mut _,
         None     => std::ptr::null_mut(),
     }
 }