]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
QA: add --afl-decoder-ppp=<file>
authorVictor Julien <victor@inliniac.net>
Tue, 29 Mar 2016 16:18:20 +0000 (18:18 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 12 Apr 2016 13:20:00 +0000 (15:20 +0200)
configure.ac
src/decode.c
src/decode.h
src/suricata.c

index e0e2efdbd6b6c1144173c58265c7e4085a4b30ed..f3741e578b7717932de3fc866e0f48c288bd652e 100644 (file)
             AC_DEFINE([AFLFUZZ_CONF_TEST], [1], [Enable special --afl-parse-rules commandline option])
             AC_DEFINE([AFLFUZZ_APPLAYER], [1], [Enable --afl-$proto-request commandline option])
             AC_DEFINE([AFLFUZZ_MIME], [1], [Enable --afl-mime commandline option])
+            AC_DEFINE([AFLFUZZ_DECODER], [1], [Enable --afl-decoder-$proto commandline option])
     ])
 
   # disable TLS on user request
index 80d603a781902454c46c29dad5dfcef4398c5c55..75159f6f32f754870fce3cba6226b48b51f09781 100644 (file)
@@ -580,6 +580,43 @@ void CaptureStatsSetup(ThreadVars *tv, CaptureStats *s)
     s->counter_ips_replaced = StatsRegisterCounter("ips.replaced", tv);
 }
 
+#ifdef AFLFUZZ_DECODER
+int DecoderParseDataFromFile(char *filename, DecoderFunc Decoder) {
+    int result = 1;
+    FILE *fp = fopen(filename, "r");
+    BUG_ON(fp == NULL);
+    uint8_t buffer[65536];
+
+    ThreadVars tv;
+    memset(&tv, 0, sizeof(tv));
+    DecodeThreadVars *dtv = DecodeThreadVarsAlloc(&tv);
+    DecodeRegisterPerfCounters(dtv, &tv);
+    StatsSetupPrivate(&tv);
+
+    while (1) {
+        int done = 0;
+        size_t result = fread(&buffer, 1, sizeof(buffer), fp);
+        if (result < sizeof(buffer))
+            done = 1;
+
+        Packet *p = PacketGetFromAlloc();
+        if (p != NULL) {
+            (void) Decoder (&tv, dtv, p, buffer, result, NULL);
+            PacketFree(p);
+        }
+
+        if (done)
+            break;
+    }
+    DecodeThreadVarsFree(&tv, dtv);
+
+    result = 0;
+    fclose(fp);
+    return result;
+
+}
+#endif
+
 /**
  * @}
  */
index 313bd3f51df77b306cd72a4d1e483ba2f8d4c746..4c83d08300c8cd7c4a0c46457e6bcf102baeeb0c 100644 (file)
@@ -907,6 +907,13 @@ int DecodeERSPAN(ThreadVars *, DecodeThreadVars *, Packet *, uint8_t *, uint16_t
 
 void AddressDebugPrint(Address *);
 
+#ifdef AFLFUZZ_DECODER
+typedef int (*DecoderFunc)(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
+         uint8_t *pkt, uint16_t len, PacketQueue *pq);
+
+int DecoderParseDataFromFile(char *filename, DecoderFunc Decoder);
+#endif
+
 /** \brief Set the No payload inspection Flag for the packet.
  *
  * \param p Packet to set the flag in
index e3edc0d49300ab3cf2541c6542e3afe04f640c8c..a81b816824103e1a18e2265c1f3636a425c75cd1 100644 (file)
@@ -1160,6 +1160,8 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
         {"afl-modbus-request", required_argument, 0 , 0},
         {"afl-modbus", required_argument, 0 , 0},
         {"afl-mime", required_argument, 0 , 0},
+
+        {"afl-decoder-ppp", required_argument, 0 , 0},
 #ifdef BUILD_UNIX_SOCKET
         {"unix-socket", optional_argument, 0, 0},
 #endif
@@ -1438,6 +1440,16 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
             } else if(strcmp((long_opts[option_index]).name, "afl-mime") == 0) {
                 //printf("arg: //%s\n", optarg);
                 exit(MimeParserDataFromFile(optarg));
+#endif
+#ifdef AFLFUZZ_DECODER
+            } else if(strcmp((long_opts[option_index]).name, "afl-decoder-ppp") == 0) {
+                StatsInit();
+                MpmTableSetup();
+                AppLayerProtoDetectSetup();
+                DefragInit();
+                FlowInitConfig(FLOW_QUIET);
+                //printf("arg: //%s\n", optarg);
+                exit(DecoderParseDataFromFile(optarg, DecodePPP));
 #endif
             } else if(strcmp((long_opts[option_index]).name, "simulate-ips") == 0) {
                 SCLogInfo("Setting IPS mode");