]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http: close file when http body limit is reached 1880/head
authorGiuseppe Longo <glongo@stamus-networks.com>
Wed, 24 Feb 2016 08:28:41 +0000 (09:28 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 24 Feb 2016 15:19:58 +0000 (16:19 +0100)
In some conditions, if stream.reassembly.depth is greater than
request/response-body-limit size, the logging output is wrong
if filestore keyword is used with http.

For example, we get:
{... "app_proto":"http","fileinfo":{"filename":"\/file.pdf","state":"CLOSED","stored":false,"size":1049292,"tx_id":0}}

"state":"CLOSED","stored":false should be "state":"TRUNCATED","stored":true.

This happens because the file state and file flags,
which is the information that determine a correct output,
are not set properly since a file is logged before and then closed (HTPFileClose).

The logic of this patch is to close a file when we are above
the limits, such that the proper state and flags can be set
and the file will be logged correctly.

src/app-layer-htp.c

index 9425525fe73c9a62fb6d0e6688ae39aee9ec97f0..457616c4ac4de17005cca78817a8c7f907e6d6d4 100644 (file)
@@ -1946,6 +1946,12 @@ int HTPCallbackResponseBodyData(htp_tx_data_t *d)
         HtpBodyAppendChunk(tx_ud, &tx_ud->response_body, (uint8_t *)d->data, len);
 
         HtpResponseBodyHandle(hstate, tx_ud, d->tx, (uint8_t *)d->data, (uint32_t)d->len);
+    } else {
+        if (tx_ud->tcflags & HTP_FILENAME_SET) {
+            SCLogDebug("closing file that was being stored");
+            (void)HTPFileClose(hstate, NULL, 0, FILE_TRUNCATED, STREAM_TOCLIENT);
+            tx_ud->tcflags &= ~HTP_FILENAME_SET;
+        }
     }
 
     /* set the new chunk flag */