]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http: fix reassembled range file accounting 7186/head
authorVictor Julien <vjulien@oisf.net>
Thu, 24 Mar 2022 15:44:10 +0000 (16:44 +0100)
committerVictor Julien <vjulien@oisf.net>
Tue, 29 Mar 2022 05:57:17 +0000 (07:57 +0200)
src/app-layer-htp-file.c
src/app-layer-htp-file.h
src/app-layer-htp.c

index bc49a25ca98dd768561444fdf48be4e6475f987a..5d4ef9add899a3625803b4817df89b2d2f8b6a8b 100644 (file)
@@ -390,7 +390,7 @@ bool HTPFileCloseHandleRange(FileContainer *files, const uint16_t flags, HttpRan
  *  \retval -1 error
  *  \retval -2 not storing files on this flow/tx
  */
-int HTPFileClose(HtpState *s, const uint8_t *data, uint32_t data_len,
+int HTPFileClose(HtpState *s, HtpTxUserData *htud, const uint8_t *data, uint32_t data_len,
         uint8_t flags, uint8_t direction)
 {
     SCEnter();
@@ -422,7 +422,10 @@ int HTPFileClose(HtpState *s, const uint8_t *data, uint32_t data_len,
     }
 
     if (s->file_range != NULL) {
-        HTPFileCloseHandleRange(files, flags, s->file_range, data, data_len);
+        bool added = HTPFileCloseHandleRange(files, flags, s->file_range, data, data_len);
+        if (added) {
+            htud->tx_data.files_opened++;
+        }
         HttpRangeFreeBlock(s->file_range);
         s->file_range = NULL;
     }
index c105652eeaea2428992dd52ccfab942a6199d0da..aa3f132ba0479679386bd2989addb73cce6b7049 100644 (file)
@@ -33,7 +33,7 @@ int HTPFileOpenWithRange(HtpState *, HtpTxUserData *, const uint8_t *, uint16_t,
 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);
+int HTPFileClose(HtpState *, HtpTxUserData *, const uint8_t *, uint32_t, uint8_t, uint8_t);
 
 void HTPFileParserRegisterTests(void);
 
index 2b7b80ef288fea70147ff056546a60ea92f4f018..fcdd7eba1d9c2c60fe3b7bae40a3cf48218240ee 100644 (file)
@@ -1414,9 +1414,8 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud,
             printf("FILEDATA (final chunk) END: \n");
 #endif
             if (!(htud->tsflags & HTP_DONTSTORE)) {
-                if (HTPFileClose(hstate, filedata, filedata_len, flags,
-                            STREAM_TOSERVER) == -1)
-                {
+                if (HTPFileClose(hstate, htud, filedata, filedata_len, flags, STREAM_TOSERVER) ==
+                        -1) {
                     goto end;
                 }
             }
@@ -1538,7 +1537,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud,
                 } else if (result == -2) {
                     htud->tsflags |= HTP_DONTSTORE;
                 } else {
-                    if (HTPFileClose(hstate, NULL, 0, 0, STREAM_TOSERVER) == -1) {
+                    if (HTPFileClose(hstate, htud, NULL, 0, 0, STREAM_TOSERVER) == -1) {
                         goto end;
                     }
                 }
@@ -1605,7 +1604,7 @@ static int HtpRequestBodyHandleMultipart(HtpState *hstate, HtpTxUserData *htud,
                     } else if (result == -2) {
                         htud->tsflags |= HTP_DONTSTORE;
                     } else {
-                        if (HTPFileClose(hstate, NULL, 0, 0, STREAM_TOSERVER) == -1) {
+                        if (HTPFileClose(hstate, htud, NULL, 0, 0, STREAM_TOSERVER) == -1) {
                             goto end;
                         }
                     }
@@ -1891,7 +1890,7 @@ static int HTPCallbackRequestBodyData(htp_tx_data_t *d)
     } else {
         if (tx_ud->tsflags & HTP_FILENAME_SET) {
             SCLogDebug("closing file that was being stored");
-            (void)HTPFileClose(hstate, NULL, 0, FILE_TRUNCATED, STREAM_TOSERVER);
+            (void)HTPFileClose(hstate, tx_ud, NULL, 0, FILE_TRUNCATED, STREAM_TOSERVER);
             tx_ud->tsflags &= ~HTP_FILENAME_SET;
         }
     }
@@ -1981,7 +1980,7 @@ static int HTPCallbackResponseBodyData(htp_tx_data_t *d)
     } else {
         if (tx_ud->tcflags & HTP_FILENAME_SET) {
             SCLogDebug("closing file that was being stored");
-            (void)HTPFileClose(hstate, NULL, 0, FILE_TRUNCATED, STREAM_TOCLIENT);
+            (void)HTPFileClose(hstate, tx_ud, NULL, 0, FILE_TRUNCATED, STREAM_TOCLIENT);
             tx_ud->tcflags &= ~HTP_FILENAME_SET;
         }
     }
@@ -2202,7 +2201,7 @@ static int HTPCallbackRequestComplete(htp_tx_t *tx)
     if (htud != NULL) {
         if (htud->tsflags & HTP_FILENAME_SET) {
             SCLogDebug("closing file that was being stored");
-            (void)HTPFileClose(hstate, NULL, 0, 0, STREAM_TOSERVER);
+            (void)HTPFileClose(hstate, htud, NULL, 0, 0, STREAM_TOSERVER);
             htud->tsflags &= ~HTP_FILENAME_SET;
             if (abs_right_edge < (uint64_t)UINT32_MAX) {
                 StreamTcpReassemblySetMinInspectDepth(
@@ -2257,7 +2256,7 @@ static int HTPCallbackResponseComplete(htp_tx_t *tx)
     if (htud != NULL) {
         if (htud->tcflags & HTP_FILENAME_SET) {
             SCLogDebug("closing file that was being stored");
-            (void)HTPFileClose(hstate, NULL, 0, 0, STREAM_TOCLIENT);
+            (void)HTPFileClose(hstate, htud, NULL, 0, 0, STREAM_TOCLIENT);
             htud->tcflags &= ~HTP_FILENAME_SET;
         }
     }