]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http2: fix file accounting for ranged files
authorVictor Julien <vjulien@oisf.net>
Fri, 25 Mar 2022 13:38:40 +0000 (14:38 +0100)
committerVictor Julien <vjulien@oisf.net>
Tue, 29 Mar 2022 05:57:17 +0000 (07:57 +0200)
Increment files_opened for tx that 'gets' reassembled ranged file

rust/src/core.rs
rust/src/http2/http2.rs
rust/src/http2/range.rs
src/app-layer-htp-file.c
src/app-layer-htp-file.h
src/rust-context.h

index 245cfd900f0547768e642d5324bde9f14ff97b3b..7a037d1ff11f8bfc9f47db7310f84349b529efb5 100644 (file)
@@ -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,
index bf80379c2f16ddfa5ca253847a8f700f176286d5..0d18a2f455d9d443b421ac88afd2c39d7bf00974 100644 (file)
@@ -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,
 
index f86e2188f9b275e83efdba24f3f8c7bc96e6d430..34217ed40bd244c2844253ed3401b039aca0a2cf 100644 (file)
@@ -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
index bdbcd2932294d6f7cadde6e1e91a935a2cf8630e..bc49a25ca98dd768561444fdf48be4e6475f987a 100644 (file)
@@ -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;
 }
 
 /**
index 66522a3f2f08cdc45dc7f20823f416a91b382f2d..c105652eeaea2428992dd52ccfab942a6199d0da 100644 (file)
@@ -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);
index 20d8ce7ef3d87f00f6ce2502672a3b0001e7b623..4c43c98d9b471eed63f8521dc835b0e19265badb 100644 (file)
@@ -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 *,