http2: fix file accounting for ranged files

Increment files_opened for tx that 'gets' reassembled ranged file
pull/7186/head
Victor Julien 3 years ago
parent b336882008
commit 6d30f4442c

@ -146,7 +146,7 @@ pub type SCHTPFileCloseHandleRange = extern "C" fn (
flags: u16,
c: *mut HttpRangeContainerBlock,
data: *const u8,
data_len: u32);
data_len: u32) -> bool;
pub type SCFileOpenFileWithId = extern "C" fn (
file_container: &FileContainer,
sbcfg: &StreamingBufferConfig,

@ -134,7 +134,7 @@ pub struct HTTP2Transaction {
decoder: decompression::HTTP2Decoder,
pub file_range: *mut HttpRangeContainerBlock,
tx_data: AppLayerTxData,
pub tx_data: AppLayerTxData,
pub ft_tc: FileTransferTracker,
ft_ts: FileTransferTracker,

@ -167,20 +167,23 @@ pub fn http2_range_append(fr: *mut HttpRangeContainerBlock, data: &[u8]) {
pub fn http2_range_close(
tx: &mut HTTP2Transaction, files: &mut FileContainer, flags: u16, data: &[u8],
) {
match unsafe { SC } {
None => panic!("BUG no suricata_config"),
Some(c) => {
(c.HTPFileCloseHandleRange)(
let added = if let Some(c) = unsafe { SC } {
let added = (c.HTPFileCloseHandleRange)(
files,
flags,
tx.file_range,
data.as_ptr(),
data.len() as u32,
);
(c.HttpRangeFreeBlock)(tx.file_range);
}
}
);
(c.HttpRangeFreeBlock)(tx.file_range);
added
} else {
false
};
tx.file_range = std::ptr::null_mut();
if added {
tx.tx_data.incr_files_opened();
}
}
// Defined in app-layer-htp-range.h

@ -344,9 +344,14 @@ end:
SCReturnInt(retval);
}
void HTPFileCloseHandleRange(FileContainer *files, const uint16_t flags, HttpRangeContainerBlock *c,
/** \brief close range, add reassembled file if possible
* \retval true if reassembled file was added
* \retval false if no reassembled file was added
*/
bool HTPFileCloseHandleRange(FileContainer *files, const uint16_t flags, HttpRangeContainerBlock *c,
const uint8_t *data, uint32_t data_len)
{
bool added = false;
if (HttpRangeAppendData(c, data, data_len) < 0) {
SCLogDebug("Failed to append data");
}
@ -361,10 +366,12 @@ void HTPFileCloseHandleRange(FileContainer *files, const uint16_t flags, HttpRan
if (ranged && files) {
/* HtpState owns the constructed file now */
FileContainerAdd(files, ranged);
added = true;
}
DEBUG_VALIDATE_BUG_ON(ranged && !files);
THashDataUnlock(c->container->hdata);
}
return added;
}
/**

@ -30,7 +30,7 @@ int HTPFileOpen(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const ui
int HTPParseContentRange(bstr *rawvalue, HTTPContentRange *range);
int HTPFileOpenWithRange(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *,
uint32_t, uint64_t, bstr *rawvalue, HtpTxUserData *htud);
void HTPFileCloseHandleRange(
bool HTPFileCloseHandleRange(
FileContainer *, const uint16_t, HttpRangeContainerBlock *, const uint8_t *, uint32_t);
int HTPFileStoreChunk(HtpState *, const uint8_t *, uint32_t, uint8_t);
int HTPFileClose(HtpState *, const uint8_t *, uint32_t, uint8_t, uint8_t);

@ -40,7 +40,7 @@ typedef struct SuricataContext_ {
void (*AppLayerParserTriggerRawStreamReassembly)(Flow *, int direction);
void (*HttpRangeFreeBlock)(HttpRangeContainerBlock *);
void (*HTPFileCloseHandleRange)(
bool (*HTPFileCloseHandleRange)(
FileContainer *, const uint16_t, HttpRangeContainerBlock *, const uint8_t *, uint32_t);
int (*FileOpenFileWithId)(FileContainer *, const StreamingBufferConfig *,

Loading…
Cancel
Save