]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/file: improve truncation handling 2940/head
authorVictor Julien <victor@inliniac.net>
Mon, 2 Oct 2017 16:34:08 +0000 (18:34 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 17 Oct 2017 07:38:46 +0000 (09:38 +0200)
rust/src/filecontainer.rs
rust/src/filetracker.rs

index 546625de949350ae8512f91d5c1a4ac6e8a42701..a57e0184f0300bcf9bf7e8cbb084485785dec485 100644 (file)
@@ -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
             }
         }
index 7e5c24a1acf3c8fe518e74e37c13b40ff524e637..0bfe1a7077140f345e7d908f8b5aafb6f3517f65 100644 (file)
@@ -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) {