diff --git a/rust/src/core.rs b/rust/src/core.rs index 245cfd900f..7a037d1ff1 100644 --- a/rust/src/core.rs +++ b/rust/src/core.rs @@ -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, diff --git a/rust/src/http2/http2.rs b/rust/src/http2/http2.rs index bf80379c2f..0d18a2f455 100644 --- a/rust/src/http2/http2.rs +++ b/rust/src/http2/http2.rs @@ -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, diff --git a/rust/src/http2/range.rs b/rust/src/http2/range.rs index f86e2188f9..34217ed40b 100644 --- a/rust/src/http2/range.rs +++ b/rust/src/http2/range.rs @@ -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 diff --git a/src/app-layer-htp-file.c b/src/app-layer-htp-file.c index bdbcd29322..bc49a25ca9 100644 --- a/src/app-layer-htp-file.c +++ b/src/app-layer-htp-file.c @@ -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; } /** diff --git a/src/app-layer-htp-file.h b/src/app-layer-htp-file.h index 66522a3f2f..c105652eea 100644 --- a/src/app-layer-htp-file.h +++ b/src/app-layer-htp-file.h @@ -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); diff --git a/src/rust-context.h b/src/rust-context.h index 20d8ce7ef3..4c43c98d9b 100644 --- a/src/rust-context.h +++ b/src/rust-context.h @@ -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 *,