]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http: add per direction config for body parsing
authorVictor Julien <victor@inliniac.net>
Fri, 13 Nov 2015 23:14:02 +0000 (00:14 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 20 May 2016 10:32:39 +0000 (12:32 +0200)
The HTPCfgDir structure is meant to contain config for per direction
body parsing parameters.

This patch stores the streaming API config.

src/app-layer-htp-body.c
src/app-layer-htp-body.h
src/app-layer-htp.c
src/app-layer-htp.h

index 53194307b4b857018e48b7619935cefdd5bb539b..65ce30ad3963b3cb9775eb0194a32ddaa912ccc8 100644 (file)
@@ -75,7 +75,8 @@ static StreamingBufferConfig default_cfg = {
  * \retval 0 ok
  * \retval -1 error
  */
-int HtpBodyAppendChunk(HtpBody *body, const uint8_t *data, uint32_t len)
+int HtpBodyAppendChunk(const HTPCfgDir *hcfg, HtpBody *body,
+                       const uint8_t *data, uint32_t len)
 {
     SCEnter();
 
@@ -86,7 +87,8 @@ int HtpBodyAppendChunk(HtpBody *body, const uint8_t *data, uint32_t len)
     }
 
     if (body->sb == NULL) {
-        body->sb = StreamingBufferInit(&default_cfg);
+        const StreamingBufferConfig *cfg = hcfg ? &hcfg->sbcfg : &default_cfg;
+        body->sb = StreamingBufferInit(cfg);
         if (body->sb == NULL)
             SCReturnInt(-1);
     }
index e7d051e8545ffd8af257f8a378a3d4ba7b75abd1..637eb07d61d17f28eafc5d688e5e514445e54041 100644 (file)
@@ -28,7 +28,7 @@
 #ifndef __APP_LAYER_HTP_BODY_H__
 #define __APP_LAYER_HTP_BODY_H__
 
-int HtpBodyAppendChunk(HtpBody *, const uint8_t *, uint32_t);
+int HtpBodyAppendChunk(const HTPCfgDir *, HtpBody *, const uint8_t *, uint32_t);
 void HtpBodyPrint(HtpBody *);
 void HtpBodyFree(HtpBody *);
 void HtpBodyPrune(HtpState *, HtpBody *, int);
index f8069c757b7b5b77fe7f9a0ff165c45294889261..00d39365de223cbe8d5291c7f76291840cb3ccea 100644 (file)
@@ -1765,7 +1765,7 @@ int HTPCallbackRequestBodyData(htp_tx_data_t *d)
         }
         SCLogDebug("len %u", len);
 
-        HtpBodyAppendChunk(&tx_ud->request_body, d->data, len);
+        HtpBodyAppendChunk(&hstate->cfg->request, &tx_ud->request_body, d->data, len);
 
         const uint8_t *chunks_buffer = NULL;
         uint32_t chunks_buffer_len = 0;
@@ -1861,7 +1861,7 @@ int HTPCallbackResponseBodyData(htp_tx_data_t *d)
         }
         SCLogDebug("len %u", len);
 
-        HtpBodyAppendChunk(&tx_ud->response_body, d->data, len);
+        HtpBodyAppendChunk(&hstate->cfg->response, &tx_ud->response_body, d->data, len);
 
         HtpResponseBodyHandle(hstate, tx_ud, d->tx, (uint8_t *)d->data, (uint32_t)d->len);
     } else {
@@ -2137,10 +2137,6 @@ static void HTPConfigSetDefaultsPhase1(HTPCfgRec *cfg_prec)
 #endif
     cfg_prec->randomize_range = HTP_CONFIG_DEFAULT_RANDOMIZE_RANGE;
 
-    cfg_prec->sbcfg.flags = 0;
-    cfg_prec->sbcfg.buf_size = cfg_prec->request_inspect_window;
-    cfg_prec->sbcfg.buf_slide = 0;
-
     htp_config_register_request_header_data(cfg_prec->cfg, HTPCallbackRequestHeaderData);
     htp_config_register_request_trailer_data(cfg_prec->cfg, HTPCallbackRequestHeaderData);
     htp_config_register_response_header_data(cfg_prec->cfg, HTPCallbackResponseHeaderData);
@@ -2213,6 +2209,23 @@ static void HTPConfigSetDefaultsPhase2(char *name, HTPCfgRec *cfg_prec)
 
     htp_config_register_request_line(cfg_prec->cfg, HTPCallbackRequestLine);
 
+    cfg_prec->request.sbcfg.flags = 0;
+    cfg_prec->request.sbcfg.buf_size = cfg_prec->request_inspect_window ?
+                                       cfg_prec->request_inspect_window : 256;
+    cfg_prec->request.sbcfg.buf_slide = 0;
+    cfg_prec->request.sbcfg.Malloc = HTPMalloc;
+    cfg_prec->request.sbcfg.Calloc = HTPCalloc;
+    cfg_prec->request.sbcfg.Realloc = HTPRealloc;
+    cfg_prec->request.sbcfg.Free = HTPFree;
+
+    cfg_prec->response.sbcfg.flags = 0;
+    cfg_prec->response.sbcfg.buf_size = cfg_prec->response_inspect_window ?
+                                        cfg_prec->response_inspect_window : 256;
+    cfg_prec->response.sbcfg.buf_slide = 0;
+    cfg_prec->response.sbcfg.Malloc = HTPMalloc;
+    cfg_prec->response.sbcfg.Calloc = HTPCalloc;
+    cfg_prec->response.sbcfg.Realloc = HTPRealloc;
+    cfg_prec->response.sbcfg.Free = HTPFree;
     return;
 }
 
@@ -5613,9 +5626,9 @@ static int HTPBodyReassemblyTest01(void)
     uint8_t chunk1[] = "--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
     uint8_t chunk2[] = "POST /uri HTTP/1.1\r\nHost: hostname.com\r\nKeep-Alive: 115\r\nAccept-Charset: utf-8\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nConnection: keep-alive\r\nContent-length: 68102\r\nReferer: http://otherhost.com\r\nAccept-Encoding: gzip\r\nContent-Type: multipart/form-data; boundary=e5a320f21416a02493a0a6f561b1c494\r\nCookie: blah\r\nAccept-Language: us\r\n\r\n--e5a320f21416a02493a0a6f561b1c494\r\nContent-Disposition: form-data; name=\"uploadfile\"; filename=\"D2GUef.jpg\"\r";
 
-    int r = HtpBodyAppendChunk(&htud.request_body, chunk1, sizeof(chunk1)-1);
+    int r = HtpBodyAppendChunk(NULL, &htud.request_body, chunk1, sizeof(chunk1)-1);
     BUG_ON(r != 0);
-    r = HtpBodyAppendChunk(&htud.request_body, chunk2, sizeof(chunk2)-1);
+    r = HtpBodyAppendChunk(NULL, &htud.request_body, chunk2, sizeof(chunk2)-1);
     BUG_ON(r != 0);
 
     const uint8_t *chunks_buffer = NULL;
index 3c7ae66cbf17aa8880bbb6ab11e42ab2e62fddd5..039b1cfe8e4ae127fa5913f9297070bc664be9fb 100644 (file)
@@ -140,6 +140,10 @@ enum {
 #define HTP_PCRE_HAS_MATCH      0x02    /**< Flag to indicate that the chunks
                                              matched on some rule */
 
+typedef struct HTPCfgDir_ {
+    StreamingBufferConfig sbcfg;
+} HTPCfgDir;
+
 /** Need a linked list in order to keep track of these */
 typedef struct HTPCfgRec_ {
     htp_cfg_t           *cfg;
@@ -160,7 +164,8 @@ typedef struct HTPCfgRec_ {
     int                 randomize_range;
     int                 http_body_inline;
 
-    StreamingBufferConfig sbcfg;
+    HTPCfgDir request;
+    HTPCfgDir response;
 } HTPCfgRec;
 
 /** Struct used to hold chunks of a body on a request */