]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/content-inspect: turn void arg into Packet
authorVictor Julien <victor@inliniac.net>
Fri, 3 May 2019 08:00:09 +0000 (10:00 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 3 May 2019 10:35:36 +0000 (12:35 +0200)
Replace the 'void *data' argument by a 'Packet *p' as this was
the only user left of the data pointer.

18 files changed:
src/detect-base64-data.c
src/detect-dce-stub-data.c
src/detect-dnp3.c
src/detect-dns-query.c
src/detect-engine-content-inspection.c
src/detect-engine-content-inspection.h
src/detect-engine-payload.c
src/detect-engine.c
src/detect-file-data.c
src/detect-filemagic.c
src/detect-filename.c
src/detect-http-header-names.c
src/detect-http-header.c
src/detect-http-start.c
src/detect-krb5-cname.c
src/detect-krb5-sname.c
src/detect-template-rust-buffer.c
src/tests/detect-engine-content-inspection.c

index 92cce96cbde21ece2a98b3e90a104deefd6e63a1..00782153c8db1b60ff20a1be9c82ac01d326c5cf 100644 (file)
@@ -63,9 +63,9 @@ int DetectBase64DataDoMatch(DetectEngineCtx *de_ctx,
 {
     if (det_ctx->base64_decoded_len) {
         return DetectEngineContentInspection(de_ctx, det_ctx, s,
-            s->sm_arrays[DETECT_SM_LIST_BASE64_DATA], f, det_ctx->base64_decoded,
+            s->sm_arrays[DETECT_SM_LIST_BASE64_DATA], NULL, f, det_ctx->base64_decoded,
             det_ctx->base64_decoded_len, 0, DETECT_CI_FLAGS_SINGLE,
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     }
 
     return 0;
index d4656bbfbb0572e0a97974b9e25b0dcba367647c..b5104f6b41c3a19e0927bf6b8f2957be06b615c0 100644 (file)
@@ -182,7 +182,6 @@ static int InspectEngineDceStubData(ThreadVars *tv,
 {
     uint32_t buffer_len = 0;
     uint8_t *buffer = NULL;
-    DCERPCState *dcerpc_state = NULL;
     uint8_t ci_flags = DETECT_CI_FLAGS_SINGLE;
 
     if (f->alproto == ALPROTO_SMB) {
@@ -190,9 +189,8 @@ static int InspectEngineDceStubData(ThreadVars *tv,
         if (rs_smb_tx_get_stub_data(tx, dir, &buffer, &buffer_len) != 1)
             goto end;
         SCLogDebug("have data!");
-    } else
-    {
-        dcerpc_state = alstate;
+    } else {
+        DCERPCState *dcerpc_state = alstate;
         if (dcerpc_state == NULL)
             goto end;
 
@@ -216,11 +214,10 @@ static int InspectEngineDceStubData(ThreadVars *tv,
     det_ctx->discontinue_matching = 0;
     det_ctx->inspection_recursion_counter = 0;
     int r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd,
-                                          f,
+                                          NULL, f,
                                           buffer, buffer_len,
                                           0, ci_flags,
-                                          DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE,
-                                          dcerpc_state);
+                                          DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     if (r == 1)
         return DETECT_ENGINE_INSPECT_SIG_MATCH;
 
index 85f8e918c9b8013dcfe5b2dbb1e7a6b0ac4f6d43..b035673507d4bb99e347eea1bfe0938e86705cac 100644 (file)
@@ -153,15 +153,15 @@ static int DetectEngineInspectDNP3Data(ThreadVars *tv, DetectEngineCtx *de_ctx,
     /* Content match - should probably be put into its own file. */
     if (flags & STREAM_TOSERVER && tx->request_buffer != NULL) {
         r = DetectEngineContentInspection(de_ctx, det_ctx, s,
-            smd, f, tx->request_buffer,
+            smd, NULL, f, tx->request_buffer,
             tx->request_buffer_len, 0, DETECT_CI_FLAGS_SINGLE,
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     }
     else if (flags & STREAM_TOCLIENT && tx->response_buffer != NULL) {
         r = DetectEngineContentInspection(de_ctx, det_ctx, s,
-            smd, f, tx->response_buffer,
+            smd, NULL, f, tx->response_buffer,
             tx->response_buffer_len, 0, DETECT_CI_FLAGS_SINGLE,
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     }
 
     SCReturnInt(r);
index 01339d8f1ebc62ad2f478ae8a1b164949229f560..4fdd727813e7bcde73ad9a2a02d099605cfa94e9 100644 (file)
@@ -121,11 +121,11 @@ static int DetectEngineInspectDnsQuery(
         det_ctx->inspection_recursion_counter = 0;
 
         const int match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
-                                              f,
+                                              NULL, f,
                                               (uint8_t *)buffer->inspect,
                                               buffer->inspect_len,
                                               buffer->inspect_offset, DETECT_CI_FLAGS_SINGLE,
-                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
         if (match == 1) {
             return DETECT_ENGINE_INSPECT_SIG_MATCH;
         }
index 582f416b956139cefae95ec4e83071c357a89000..473e8a2f55f72377d3975c1613e2bfd911939aea 100644 (file)
@@ -82,6 +82,7 @@
  * \param det_ctx         Detection engine thread context
  * \param s               Signature to inspect
  * \param sm              SigMatch to inspect
+ * \param p               Packet. Can be NULL.
  * \param f               Flow (for pcre flowvar storage)
  * \param buffer          Ptr to the buffer to inspect
  * \param buffer_len      Length of the payload
  * \param inspection_mode Refers to the engine inspection mode we are currently
  *                        inspecting.  Can be payload, stream, one of the http
  *                        buffer inspection modes or dce inspection mode.
- * \param data            Used to send some custom data.  For example in
- *                        payload inspection mode, data contains packet ptr,
- *                        and under dce inspection mode, contains dce state.
+ * \param flags           DETECT_CI_FLAG_*
  *
  *  \retval 0 no match
  *  \retval 1 match
  */
 int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
                                   const Signature *s, const SigMatchData *smd,
-                                  Flow *f,
+                                  Packet *p, Flow *f,
                                   uint8_t *buffer, uint32_t buffer_len,
                                   uint32_t stream_start_offset, uint8_t flags,
-                                  uint8_t inspection_mode, void *data)
+                                  uint8_t inspection_mode)
 {
     SCEnter();
     KEYWORD_PROFILING_START;
@@ -333,8 +332,8 @@ int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx
                      * search for another occurence of this content and see
                      * if the others match then until we run out of matches */
                     int r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd+1,
-                            f, buffer, buffer_len, stream_start_offset, flags,
-                            inspection_mode, data);
+                            p, f, buffer, buffer_len, stream_start_offset, flags,
+                            inspection_mode);
                     if (r == 1) {
                         SCReturnInt(1);
                     }
@@ -415,9 +414,6 @@ int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx
 
         det_ctx->pcre_match_start_offset = 0;
         do {
-            Packet *p = NULL;
-            if (inspection_mode == DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD)
-                p = (Packet *)data;
             r = DetectPcrePayloadMatch(det_ctx, s, smd, p, f,
                                        buffer, buffer_len);
             if (r == 0) {
@@ -437,8 +433,8 @@ int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx
              * search for another occurence of this pcre and see
              * if the others match, until we run out of matches */
             r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd+1,
-                    f, buffer, buffer_len, stream_start_offset, flags,
-                    inspection_mode, data);
+                    p, f, buffer, buffer_len, stream_start_offset, flags,
+                    inspection_mode);
             if (r == 1) {
                 SCReturnInt(1);
             }
@@ -618,8 +614,8 @@ match:
     if (!smd->is_last) {
         KEYWORD_PROFILING_END(det_ctx, smd->type, 1);
         int r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd+1,
-                f, buffer, buffer_len, stream_start_offset, flags,
-                inspection_mode, data);
+                p, f, buffer, buffer_len, stream_start_offset, flags,
+                inspection_mode);
         SCReturnInt(r);
     }
 final_match:
index 7b567fb08eeac1cfbc58c6922d84ff6195354267..bc0229cf300d6e62434fe97963c515566e1657dd 100644 (file)
@@ -46,10 +46,10 @@ enum {
 
 int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
                                   const Signature *s, const SigMatchData *smd,
-                                  Flow *f,
+                                  Packet *p, Flow *f,
                                   uint8_t *buffer, uint32_t buffer_len,
                                   uint32_t stream_start_offset, uint8_t flags,
-                                  uint8_t inspection_mode, void *data);
+                                  uint8_t inspection_mode);
 
 void DetectEngineContentInspectionRegisterTests(void);
 
index fbdf3da5b39959cdac79c823b16097aaec3292dd..add1ba6a3d9d7f0d1a623bae9b22429b02cec606 100644 (file)
@@ -165,9 +165,10 @@ int DetectEngineInspectPacketPayload(DetectEngineCtx *de_ctx,
     det_ctx->inspection_recursion_counter = 0;
     det_ctx->replist = NULL;
 
-    r = DetectEngineContentInspection(de_ctx, det_ctx, s, s->sm_arrays[DETECT_SM_LIST_PMATCH],
-                                      f, p->payload, p->payload_len, 0, DETECT_CI_FLAGS_SINGLE,
-                                      DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD, p);
+    r = DetectEngineContentInspection(de_ctx, det_ctx,
+            s, s->sm_arrays[DETECT_SM_LIST_PMATCH],
+            p, f, p->payload, p->payload_len, 0,
+            DETECT_CI_FLAGS_SINGLE, DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD);
     if (r == 1) {
         SCReturnInt(1);
     }
@@ -208,8 +209,8 @@ static int DetectEngineInspectStreamUDPPayload(DetectEngineCtx *de_ctx,
     det_ctx->replist = NULL;
 
     r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd,
-            f, p->payload, p->payload_len, 0, DETECT_CI_FLAGS_SINGLE,
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD, p);
+            p, f, p->payload, p->payload_len, 0, DETECT_CI_FLAGS_SINGLE,
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD);
     if (r == 1) {
         SCReturnInt(1);
     }
@@ -238,8 +239,8 @@ static int StreamContentInspectFunc(void *cb_data, const uint8_t *data, const ui
 
     r = DetectEngineContentInspection(smd->de_ctx, smd->det_ctx,
             smd->s, smd->s->sm_arrays[DETECT_SM_LIST_PMATCH],
-            smd->f, (uint8_t *)data, data_len, 0, 0, //TODO
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM, NULL);
+            NULL, smd->f, (uint8_t *)data, data_len, 0, 0, //TODO
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM);
     if (r == 1) {
         SCReturnInt(1);
     }
@@ -296,8 +297,8 @@ static int StreamContentInspectEngineFunc(void *cb_data, const uint8_t *data, co
 
     r = DetectEngineContentInspection(smd->de_ctx, smd->det_ctx,
             smd->s, smd->smd,
-            smd->f, (uint8_t *)data, data_len, 0, 0, // TODO
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM, NULL);
+            NULL, smd->f, (uint8_t *)data, data_len, 0, 0, // TODO
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM);
     if (r == 1) {
         SCReturnInt(1);
     }
index 7d83842d840d41715e7327760331394ebe114e85..416a2fc68e5dc6d52199b2819676944aaff0827f 100644 (file)
@@ -1281,9 +1281,9 @@ int DetectEngineInspectBufferGeneric(
      * transaction at the app layer */
     int r = DetectEngineContentInspection(de_ctx, det_ctx,
                                           s, engine->smd,
-                                          f,
+                                          NULL, f,
                                           (uint8_t *)data, data_len, offset, ci_flags,
-                                          DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+                                          DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     if (r == 1) {
         return DETECT_ENGINE_INSPECT_SIG_MATCH;
     } else {
index 9237120cb97b772017ebc66e71a3d0b6a9f458bd..a4f9ed617d43a411264d416c52e3b5a553901cc1 100644 (file)
@@ -444,11 +444,11 @@ static int DetectEngineInspectFiledata(
         det_ctx->discontinue_matching = 0;
         det_ctx->inspection_recursion_counter = 0;
         match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
-                                              f,
+                                              NULL, f,
                                               (uint8_t *)buffer->inspect,
                                               buffer->inspect_len,
                                               buffer->inspect_offset, ciflags,
-                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
         if (match == 1) {
             r = 1;
             break;
index 9aefb60b28c2de5424a4efbf9c28a709a5e9ee7e..bd9b34993ef1fb9372d18151f1aff662d8a08661 100644 (file)
@@ -556,11 +556,11 @@ static int DetectEngineInspectFilemagic(
         det_ctx->discontinue_matching = 0;
         det_ctx->inspection_recursion_counter = 0;
         int match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
-                                              f,
+                                              NULL, f,
                                               (uint8_t *)buffer->inspect,
                                               buffer->inspect_len,
                                               buffer->inspect_offset, DETECT_CI_FLAGS_SINGLE,
-                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
         if (match == 1) {
             return DETECT_ENGINE_INSPECT_SIG_MATCH;
         } else {
index 3538e9206808c10bc8e2553a46b7d3c7b15a3ae7..e57f051a9cad61e45f1bba885bae6f42b9d3b7d1 100644 (file)
@@ -402,11 +402,11 @@ static int DetectEngineInspectFilename(
         det_ctx->discontinue_matching = 0;
         det_ctx->inspection_recursion_counter = 0;
         int match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
-                                              f,
+                                              NULL, f,
                                               (uint8_t *)buffer->inspect,
                                               buffer->inspect_len,
                                               buffer->inspect_offset, DETECT_CI_FLAGS_SINGLE,
-                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
         if (match == 1) {
             return DETECT_ENGINE_INSPECT_SIG_MATCH;
         } else {
index 5d065e1bace836d96740988c51da5ffb9e03f96d..67bc1bb361ea6a571506f945e0d68a8458cdbf38 100644 (file)
@@ -344,9 +344,9 @@ static int InspectEngineHttpHeaderNames(
     det_ctx->discontinue_matching = 0;
     det_ctx->inspection_recursion_counter = 0;
     int r = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
-            f, (uint8_t *)data, data_len, offset,
+            NULL, f, (uint8_t *)data, data_len, offset,
             DETECT_CI_FLAGS_SINGLE,
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     if (r == 1)
         return DETECT_ENGINE_INSPECT_SIG_MATCH;
 
index 9a00f64ccb47464c2e0f338cf3934e6f8eddb97b..b2aa0efd225fe775f4ca5c75e2ddc339a02baec3 100644 (file)
@@ -190,11 +190,9 @@ static int DetectEngineInspectBufferHttpHeader(
 
     /* Inspect all the uricontents fetched on each
      * transaction at the app layer */
-    int r = DetectEngineContentInspection(de_ctx, det_ctx,
-                                          s, engine->smd,
-                                          f,
-                                          (uint8_t *)data, data_len, offset, DETECT_CI_FLAGS_SINGLE,
-                                          DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+    int r = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
+            NULL, f, (uint8_t *)data, data_len, offset,
+            DETECT_CI_FLAGS_SINGLE, DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     SCLogDebug("r = %d", r);
     if (r == 1) {
         return DETECT_ENGINE_INSPECT_SIG_MATCH;
index 25d499003a4efbb767820c91f78d8af0a3556863..c7776bd14952c8fd03e494ea7d25f9ad81a57292 100644 (file)
@@ -341,9 +341,9 @@ static int InspectEngineHttpStart(
     det_ctx->discontinue_matching = 0;
     det_ctx->inspection_recursion_counter = 0;
     int r = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
-            f, (uint8_t *)data, data_len, offset,
+            NULL, f, (uint8_t *)data, data_len, offset,
             DETECT_CI_FLAGS_SINGLE,
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     if (r == 1)
         return DETECT_ENGINE_INSPECT_SIG_MATCH;
 
index a37441f052a6affee0f3a7f4840e3f130bc55d46..0a562e467c9c1e51adac1761be524a3e65174e30 100644 (file)
@@ -109,11 +109,11 @@ static int DetectEngineInspectKrb5CName(
         det_ctx->inspection_recursion_counter = 0;
 
         const int match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
-                                              f,
+                                              NULL, f,
                                               (uint8_t *)buffer->inspect,
                                               buffer->inspect_len,
                                               buffer->inspect_offset, DETECT_CI_FLAGS_SINGLE,
-                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
         if (match == 1) {
             return DETECT_ENGINE_INSPECT_SIG_MATCH;
         }
index 5a919bfb2adea9b83177fbc97ed37245e627ad82..d5f0bf5677f0945725fa29fee8bfec1987a7df2c 100644 (file)
@@ -109,11 +109,11 @@ static int DetectEngineInspectKrb5SName(
         det_ctx->inspection_recursion_counter = 0;
 
         const int match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
-                                              f,
+                                              NULL, f,
                                               (uint8_t *)buffer->inspect,
                                               buffer->inspect_len,
                                               buffer->inspect_offset, DETECT_CI_FLAGS_SINGLE,
-                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+                                              DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
         if (match == 1) {
             return DETECT_ENGINE_INSPECT_SIG_MATCH;
         }
index 7d876a3a3ccda47cb30007eead3ba1e62864f84e..4a813af521b0bc77be240c14f16876ab94865b37 100644 (file)
@@ -117,8 +117,8 @@ static int DetectEngineInspectTemplateRustBuffer(ThreadVars *tv,
 
     if (data != NULL) {
         ret = DetectEngineContentInspection(de_ctx, det_ctx, s, smd,
-            f, (uint8_t *)data, data_len, 0, DETECT_CI_FLAGS_SINGLE,
-            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
+            NULL, f, (uint8_t *)data, data_len, 0, DETECT_CI_FLAGS_SINGLE,
+            DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE);
     }
 
     SCLogNotice("Returning %d.", ret);
index 1f9e87ad7bd41742d466d08c2a78b1f1c1a32d73..69389e0afbe62e60a81dceca425cad7ccd754ea1 100644 (file)
@@ -47,9 +47,9 @@
     DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx);                       \
     FAIL_IF_NULL(det_ctx);                                                                  \
     int r = DetectEngineContentInspection(de_ctx, det_ctx,                                  \
-                s, s->sm_arrays[DETECT_SM_LIST_PMATCH], &f,                                 \
+                s, s->sm_arrays[DETECT_SM_LIST_PMATCH], NULL, &f,                           \
                 (uint8_t *)(buf), (buflen), 0, DETECT_CI_FLAGS_SINGLE,                      \
-                DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD, NULL);                       \
+                DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD);                             \
     FAIL_IF_NOT(r == (match));                                                              \
     FAIL_IF_NOT(det_ctx->inspection_recursion_counter == (steps));                          \
     DetectEngineThreadCtxDeinit(&tv, det_ctx);                                              \