/// UNSAFE !
#[macro_export]
macro_rules! build_slice {
- ($buf:ident, $len:expr) => ( unsafe{ std::slice::from_raw_parts($buf, $len) } );
+ ($buf:ident, $len:expr) => (
+ if $buf.is_null() && $len == 0 {
+ &[]
+ } else {
+ unsafe{ std::slice::from_raw_parts($buf, $len) }
+ }
+ );
}
/// Cast pointer to a variable, as a mutable reference to an object
_data: *mut std::os::raw::c_void)
-> AppLayerResult
{
- let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
+ let buf = build_slice!(input, input_len as usize);
SCLogDebug!("parsing {} bytes of request data", input_len);
state.update_ts(flow.get_last_time().as_secs());
-> AppLayerResult
{
SCLogDebug!("parsing {} bytes of response data", input_len);
- let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
+ let buf = build_slice!(input, input_len as usize);
state.update_ts(flow.get_last_time().as_secs());
state.parse_tcp_data_tc(buf)
_data: *mut std::os::raw::c_void)
-> AppLayerResult
{
- let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
+ let buf = build_slice!(input, input_len as usize);
SCLogDebug!("parsing {} bytes of request data", input_len);
state.parse_udp_ts(buf)
}
-> AppLayerResult
{
SCLogDebug!("parsing {} bytes of response data", input_len);
- let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
+ let buf = build_slice!(input, input_len as usize);
state.parse_udp_tc(buf)
}
flags: u8)
-> AppLayerResult
{
- let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
+ let buf = build_slice!(input, input_len as usize);
SCLogDebug!("parsing {} bytes of request data", input_len);
/* START with MISTREAM set: record might be starting the middle. */
-> AppLayerResult
{
SCLogDebug!("parsing {} bytes of response data", input_len);
- let buf = unsafe{std::slice::from_raw_parts(input, input_len as usize)};
+ let buf = build_slice!(input, input_len as usize);
/* START with MISTREAM set: record might be starting the middle. */
if flags & (STREAM_START|STREAM_MIDSTREAM) == (STREAM_START|STREAM_MIDSTREAM) {