]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http2: fix leak with range files
authorPhilippe Antoine <pantoine@oisf.net>
Sat, 21 Jan 2023 17:19:47 +0000 (18:19 +0100)
committerVictor Julien <vjulien@oisf.net>
Thu, 26 Jan 2023 05:58:53 +0000 (06:58 +0100)
Ticket: #5808

May have been introduced by a24d7dc45c818054f97448ce42ca9ba270b3b8e4

Function http2_range_open expects to be called only when
tx.file_range is nil. One condition to ensure this is to check
that we are beginning the files contents. The filetracker field
file_open is not fit for this, as it may be reset to false.

rust/src/filetracker.rs
rust/src/http2/http2.rs

index 4585608d9b7f975077ac33404611987ece3f99d9..dbc80a682ee93c8bd98402afca0e797bbea4e855 100644 (file)
@@ -85,6 +85,10 @@ impl FileTransferTracker {
         !self.file_open
     }
 
+    pub fn is_initialized(&self) -> bool {
+        return self.file_open || self.file_is_truncated;
+    }
+
     fn open(&mut self, config: &'static SuricataFileContext, name: &[u8]) -> i32
     {
         let r = self.file.file_open(config, self.track_id, name, self.file_flags);
index 63032cc5b6f4694630348dd549b7774814c0be77..a24b8a058158e1f0a9f0d7ffd1e66077af5524e1 100644 (file)
@@ -219,7 +219,8 @@ impl HTTP2Transaction {
         let xid: u32 = self.tx_id as u32;
         if dir == Direction::ToClient {
             self.ft_tc.tx_id = self.tx_id - 1;
-            if !self.ft_tc.file_open {
+            // Check that we are at the beginning of the file
+            if !self.ft_tc.is_initialized() {
                 // we are now sure that new_chunk will open a file
                 // even if it may close it right afterwards
                 self.tx_data.incr_files_opened();