tftp: use destate

And avoids memory leaks on it

Ticket #4848
pull/7288/head
Philippe Antoine 4 years ago committed by Shivani Bhardwaj
parent 6075cc157b
commit 8498999c6a

@ -23,6 +23,8 @@ use std::str;
use std;
use std::mem::transmute;
use crate::core;
use crate::applayer::AppLayerTxData;
#[derive(Debug)]
@ -32,6 +34,7 @@ pub struct TFTPTransaction {
pub mode : String,
id: u64,
tx_data: AppLayerTxData,
pub de_state: Option<*mut core::DetectEngineState>,
}
pub struct TFTPState {
@ -62,6 +65,7 @@ impl TFTPTransaction {
mode : mode.to_lowercase(),
id : 0,
tx_data: AppLayerTxData::new(),
de_state: None,
}
}
pub fn is_mode_ok(&self) -> bool {
@ -70,6 +74,21 @@ impl TFTPTransaction {
_ => false
}
}
pub fn free(&mut self) {
match self.de_state {
Some(state) => {
core::sc_detect_engine_state_free(state);
}
None => { },
}
}
}
impl Drop for TFTPTransaction {
fn drop(&mut self) {
self.free();
}
}
#[no_mangle]
@ -123,6 +142,31 @@ named!(pub tftp_request<TFTPTransaction>,
)
);
#[no_mangle]
pub extern "C" fn rs_tftp_state_set_tx_detect_state(
tx: *mut std::os::raw::c_void,
de_state: &mut core::DetectEngineState) -> std::os::raw::c_int
{
let tx = cast_pointer!(tx, TFTPTransaction);
tx.de_state = Some(de_state);
return 0;
}
#[no_mangle]
pub extern "C" fn rs_tftp_state_get_tx_detect_state(
tx: *mut std::os::raw::c_void)
-> *mut core::DetectEngineState
{
let tx = cast_pointer!(tx, TFTPTransaction);
match tx.de_state {
Some(ds) => {
return ds;
},
None => {
return std::ptr::null_mut();
}
}
}
#[no_mangle]
pub extern "C" fn rs_tftp_request(state: &mut TFTPState,

@ -170,13 +170,13 @@ static int TFTPGetStateProgress(void *tx, uint8_t direction)
static DetectEngineState *TFTPGetTxDetectState(void *vtx)
{
return NULL;
return rs_tftp_state_get_tx_detect_state(vtx);
}
static int TFTPSetTxDetectState(void *vtx,
DetectEngineState *s)
{
return 0;
return rs_tftp_state_set_tx_detect_state(vtx, s);
}
void RegisterTFTPParsers(void)
@ -252,7 +252,6 @@ void RegisterTFTPParsers(void)
AppLayerParserRegisterGetTx(IPPROTO_UDP, ALPROTO_TFTP,
TFTPGetTx);
/* What is this being registered for? */
AppLayerParserRegisterDetectStateFuncs(IPPROTO_UDP, ALPROTO_TFTP,
TFTPGetTxDetectState,
TFTPSetTxDetectState);

Loading…
Cancel
Save