]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
QA: expose Mime decoding API to commandline using --afl-mime=<file>
authorVictor Julien <victor@inliniac.net>
Fri, 25 Mar 2016 13:25:22 +0000 (14:25 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 12 Apr 2016 13:19:59 +0000 (15:19 +0200)
configure.ac
src/suricata.c
src/util-decode-mime.c
src/util-decode-mime.h

index 47fe5e942deea30064da4a879aaba56fb2aa9d67..e0e2efdbd6b6c1144173c58265c7e4085a4b30ed 100644 (file)
             AC_DEFINE([AFLFUZZ_PCAP_RUNMODE], [1], [Enable special AFL 'single' runmode])
             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])
     ])
 
   # disable TLS on user request
index d3b069ef6a541c0a4af46f9e4ebd36ca66c63693..e3edc0d49300ab3cf2541c6542e3afe04f640c8c 100644 (file)
@@ -1159,6 +1159,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
         {"afl-smb", required_argument, 0 , 0},
         {"afl-modbus-request", required_argument, 0 , 0},
         {"afl-modbus", required_argument, 0 , 0},
+        {"afl-mime", required_argument, 0 , 0},
 #ifdef BUILD_UNIX_SOCKET
         {"unix-socket", optional_argument, 0, 0},
 #endif
@@ -1432,6 +1433,11 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
                 AppLayerParserSetup();
                 RegisterModbusParsers();
                 exit(AppLayerParserFromFile(ALPROTO_MODBUS, optarg));
+#endif
+#ifdef AFLFUZZ_MIME
+            } else if(strcmp((long_opts[option_index]).name, "afl-mime") == 0) {
+                //printf("arg: //%s\n", optarg);
+                exit(MimeParserDataFromFile(optarg));
 #endif
             } else if(strcmp((long_opts[option_index]).name, "simulate-ips") == 0) {
                 SCLogInfo("Setting IPS mode");
index 8ba56b6f1c04e5a46e77f15ab7aba5ef8a76bc06..7d8e888437807e82872f10550e7b68f69afc6d54 100644 (file)
@@ -2614,6 +2614,52 @@ MimeDecEntity * MimeDecParseFullMsg(const uint8_t *buf, uint32_t blen, void *dat
     return msg;
 }
 
+#ifdef AFLFUZZ_MIME
+static int MimeParserDataFromFileCB(const uint8_t *chunk, uint32_t len,
+        MimeDecParseState *state)
+{
+    return MIME_DEC_OK;
+}
+
+int MimeParserDataFromFile(char *filename)
+{
+    int result = 1;
+    FILE *fp = fopen(filename, "r");
+    BUG_ON(fp == NULL);
+    uint8_t buffer[256];
+
+    uint32_t line_count = 0;
+
+    MimeDecParseState *state = MimeDecInitParser(&line_count,
+            MimeParserDataFromFileCB);
+
+    while (1) {
+        int done = 0;
+        size_t result = fread(&buffer, 1, sizeof(buffer), fp);
+        if (result < sizeof(buffer))
+            done = 1;
+
+        (void) MimeDecParseLine(buffer, result, 1, state);
+
+        if (done)
+            break;
+    }
+
+    /* Completed */
+    (void)MimeDecParseComplete(state);
+
+    if (state->msg) {
+        MimeDecFreeEntity(state->msg);
+    }
+    /* De Init parser */
+    MimeDecDeInitParser(state);
+
+    result = 0;
+    fclose(fp);
+    return result;
+}
+#endif
+
 #ifdef UNITTESTS
 
 /* Helper body chunk callback function */
index 02b3bb13dd95fbfd5a8670856f30d2fa69ca691f..0e5fb7cb0516dd8d560935fd4f3c8443e2fc291e 100644 (file)
@@ -239,6 +239,10 @@ MimeDecEntity * MimeDecParseFullMsg(const uint8_t *buf, uint32_t blen, void *dat
         int (*DataChunkProcessorFunc)(const uint8_t *chunk, uint32_t len, MimeDecParseState *state));
 const char *MimeDecParseStateGetStatus(MimeDecParseState *state);
 
+#ifdef AFLFUZZ_MIME
+int MimeParserDataFromFile(char *filename);
+#endif
+
 /* Test functions */
 void MimeDecRegisterTests(void);