Skip to content

Commit

Permalink
range: prevents memory leak of file from HTTP2
Browse files Browse the repository at this point in the history
If a HTTP2 transaction gets freed before the end of the range
request, we need to have the files container which is in
the state, to transfer owernship of this file to the files
container.

Ticket: 4811
  • Loading branch information
catenacyber authored and victorjulien committed Nov 22, 2021
1 parent 1564942 commit c023116
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rust/src/http2/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,23 @@ impl HTTP2State {
if tx.tx_id == tx_id + 1 {
found = true;
index = i;
// this should be in HTTP2Transaction::free
// but we need state's file container cf https://redmine.openinfosecfoundation.org/issues/4444
if !tx.file_range.is_null() {
match unsafe { SC } {
None => panic!("BUG no suricata_config"),
Some(c) => {
(c.HTPFileCloseHandleRange)(
&mut self.files.files_tc,
0,
tx.file_range,
std::ptr::null_mut(),
0,
);
(c.HttpRangeFreeBlock)(tx.file_range);
}
}
}
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app-layer-htp-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ void HTPFileCloseHandleRange(FileContainer *files, const uint16_t flags, HttpRan
/* HtpState owns the constructed file now */
FileContainerAdd(files, ranged);
}
DEBUG_VALIDATE_BUG_ON(ranged && !files);
THashDataUnlock(c->container->hdata);
}
}
Expand Down

0 comments on commit c023116

Please sign in to comment.