Skip to content

Commit

Permalink
http2: fix leak with range files
Browse files Browse the repository at this point in the history
Ticket: OISF#5808

May have been introduced by a24d7dc

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.
  • Loading branch information
catenacyber authored and victorjulien committed Jan 26, 2023
1 parent a0fc00b commit ba99241
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rust/src/filetracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion rust/src/http2/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ba99241

Please sign in to comment.