From: Victor Julien Date: Tue, 29 Mar 2016 16:18:20 +0000 (+0200) Subject: QA: add --afl-decoder-ppp= X-Git-Tag: suricata-3.1RC1~260 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d16590639798ffed6a6b078aecc074c97ee1b694;p=thirdparty%2Fsuricata.git QA: add --afl-decoder-ppp= --- diff --git a/configure.ac b/configure.ac index e0e2efdbd6..f3741e578b 100644 --- a/configure.ac +++ b/configure.ac @@ -269,6 +269,7 @@ 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 diff --git a/src/decode.c b/src/decode.c index 80d603a781..75159f6f32 100644 --- a/src/decode.c +++ b/src/decode.c @@ -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 + /** * @} */ diff --git a/src/decode.h b/src/decode.h index 313bd3f51d..4c83d08300 100644 --- a/src/decode.h +++ b/src/decode.h @@ -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 diff --git a/src/suricata.c b/src/suricata.c index e3edc0d493..a81b816824 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -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");