From d9e5dfa1f0e5170b7d493b89c1c95592a6fe82cb Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 2 Oct 2017 18:34:08 +0200 Subject: [PATCH] rust/file: improve truncation handling --- rust/src/filecontainer.rs | 10 ---------- rust/src/filetracker.rs | 26 +++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/rust/src/filecontainer.rs b/rust/src/filecontainer.rs index 546625de94..a57e0184f0 100644 --- a/rust/src/filecontainer.rs +++ b/rust/src/filecontainer.rs @@ -54,10 +54,6 @@ impl FileContainer { (c.FileOpenFile)(&self, cfg.files_sbcfg, *track_id, name.as_ptr(), name.len() as u16, ptr::null(), 0u32, flags); - - //if !res { - // panic!("c.fn_fileopenfile failed"); - //} 0 } } @@ -85,9 +81,6 @@ impl FileContainer { r }, }; - if res != 0 { - panic!("c.fn_fileappenddata failed"); - } res } } @@ -100,9 +93,6 @@ impl FileContainer { None => panic!("BUG no suricata_config"), Some(c) => { let res = (c.FileCloseFile)(&self, *track_id, ptr::null(), 0u32, flags); - if res != 0 { - panic!("c.fn_fileclosefile failed"); - } res } } diff --git a/rust/src/filetracker.rs b/rust/src/filetracker.rs index 7e5c24a1ac..0bfe1a7077 100644 --- a/rust/src/filetracker.rs +++ b/rust/src/filetracker.rs @@ -199,7 +199,13 @@ impl FileTransferTracker { if self.chunk_is_ooo == false { let res = files.file_append(&self.track_id, d, is_gap); - if res != 0 { panic!("append failed"); } + match res { + 0 => { }, + -2 => { + self.file_is_truncated = true; + }, + _ => { panic!("append failed with code {}", res); }, + } self.tracked += self.chunk_left as u64; } else { @@ -238,7 +244,15 @@ impl FileTransferTracker { match self.chunks.remove(&self.tracked) { Some(c) => { let res = files.file_append(&self.track_id, &c.chunk, c.contains_gap); - if res != 0 { panic!("append failed: files.file_append() returned {}", res); } + match res { + 0 => { }, + -2 => { + self.file_is_truncated = true; + }, + _ => { + panic!("append failed: files.file_append() returned {}", res); + }, + } self.tracked += c.chunk.len() as u64; self.cur_ooo -= c.chunk.len() as u64; @@ -269,7 +283,13 @@ impl FileTransferTracker { } else { if self.chunk_is_ooo == false { let res = files.file_append(&self.track_id, data, is_gap); - if res != 0 { panic!("append failed"); } + match res { + 0 => { }, + -2 => { + self.file_is_truncated = true; + }, + _ => { panic!("append failed with code {}", res); }, + } self.tracked += data.len() as u64; } else { let c = match self.chunks.entry(self.cur_ooo_chunk_offset) {