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, flags: u16,
c: *mut HttpRangeContainerBlock, c: *mut HttpRangeContainerBlock,
data: *const u8, data: *const u8,
data_len: u32); data_len: u32) -> bool;
pub type SCFileOpenFileWithId = extern "C" fn ( pub type SCFileOpenFileWithId = extern "C" fn (
file_container: &FileContainer, file_container: &FileContainer,
sbcfg: &StreamingBufferConfig, sbcfg: &StreamingBufferConfig,

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

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

@ -344,9 +344,14 @@ end:
SCReturnInt(retval); 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) const uint8_t *data, uint32_t data_len)
{ {
bool added = false;
if (HttpRangeAppendData(c, data, data_len) < 0) { if (HttpRangeAppendData(c, data, data_len) < 0) {
SCLogDebug("Failed to append data"); SCLogDebug("Failed to append data");
} }
@ -361,10 +366,12 @@ void HTPFileCloseHandleRange(FileContainer *files, const uint16_t flags, HttpRan
if (ranged && files) { if (ranged && files) {
/* HtpState owns the constructed file now */ /* HtpState owns the constructed file now */
FileContainerAdd(files, ranged); FileContainerAdd(files, ranged);
added = true;
} }
DEBUG_VALIDATE_BUG_ON(ranged && !files); DEBUG_VALIDATE_BUG_ON(ranged && !files);
THashDataUnlock(c->container->hdata); 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 HTPParseContentRange(bstr *rawvalue, HTTPContentRange *range);
int HTPFileOpenWithRange(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *, int HTPFileOpenWithRange(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t, const uint8_t *,
uint32_t, uint64_t, bstr *rawvalue, HtpTxUserData *htud); uint32_t, uint64_t, bstr *rawvalue, HtpTxUserData *htud);
void HTPFileCloseHandleRange( bool HTPFileCloseHandleRange(
FileContainer *, const uint16_t, HttpRangeContainerBlock *, const uint8_t *, uint32_t); FileContainer *, const uint16_t, HttpRangeContainerBlock *, const uint8_t *, uint32_t);
int HTPFileStoreChunk(HtpState *, const uint8_t *, uint32_t, uint8_t); int HTPFileStoreChunk(HtpState *, const uint8_t *, uint32_t, uint8_t);
int HTPFileClose(HtpState *, const uint8_t *, uint32_t, uint8_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 (*AppLayerParserTriggerRawStreamReassembly)(Flow *, int direction);
void (*HttpRangeFreeBlock)(HttpRangeContainerBlock *); void (*HttpRangeFreeBlock)(HttpRangeContainerBlock *);
void (*HTPFileCloseHandleRange)( bool (*HTPFileCloseHandleRange)(
FileContainer *, const uint16_t, HttpRangeContainerBlock *, const uint8_t *, uint32_t); FileContainer *, const uint16_t, HttpRangeContainerBlock *, const uint8_t *, uint32_t);
int (*FileOpenFileWithId)(FileContainer *, const StreamingBufferConfig *, int (*FileOpenFileWithId)(FileContainer *, const StreamingBufferConfig *,

Loading…
Cancel
Save