]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
fuzz: use fuzzing confyaml for protodetect target 7199/head
authorPhilippe Antoine <contact@catenacyber.fr>
Wed, 15 Dec 2021 19:48:47 +0000 (20:48 +0100)
committerShivani Bhardwaj <shivanib134@gmail.com>
Sat, 2 Apr 2022 07:14:56 +0000 (12:44 +0530)
As is done for other targets,
so that all app-layer protocols are enabled,
even the ones disabled by default such as enip

And resets protocol detection every time we try
so that probing_parser_toserver_alproto_masks are fresh.

(cherry picked from commit 09c84d0c26d58e4750ef2114699c9324b561bf4e)

src/tests/fuzz/fuzz_applayerprotodetectgetproto.c

index bca53e14887db8c857c4d7c9cacd47b4f9fe7070..ec6da106f439c7f4a064e6e73ece16be275737c0 100644 (file)
 #include "flow-util.h"
 #include "app-layer-parser.h"
 #include "util-unittest-helper.h"
-
+#include "conf-yaml-loader.h"
 
 #define HEADER_LEN 6
 
 //rule of thumb constant, so as not to timeout target
 #define PROTO_DETECT_MAX_LEN 1024
 
+#include "confyaml.c"
+
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
 
 AppLayerProtoDetectThreadCtx *alpd_tctx = NULL;
@@ -37,6 +39,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         //global init
         InitGlobal();
         run_mode = RUNMODE_UNITTEST;
+        if (ConfYamlLoadString(configNoChecksum, strlen(configNoChecksum)) != 0) {
+            abort();
+        }
         MpmTableSetup();
         SpmTableSetup();
         AppLayerProtoDetectSetup();
@@ -62,7 +67,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
          * Otherwise, we have evasion with TCP splitting
          */
         for (size_t i = 0; i < size-HEADER_LEN && i < PROTO_DETECT_MAX_LEN; i++) {
-            alproto2 = AppLayerProtoDetectGetProto(alpd_tctx, f, data+HEADER_LEN, i, f->proto, data[0], &reverse);
+            // reset detection at each try cf probing_parser_toserver_alproto_masks
+            AppLayerProtoDetectReset(f);
+            alproto2 = AppLayerProtoDetectGetProto(
+                    alpd_tctx, f, data + HEADER_LEN, i, f->proto, data[0], &reverse);
             if (alproto2 != ALPROTO_UNKNOWN && alproto2 != alproto) {
                 printf("Failed with input length %" PRIuMAX " versus %" PRIuMAX
                        ", found %s instead of %s\n",