QA: expose Mime decoding API to commandline using --afl-mime=<file>

pull/2002/merge
Victor Julien 9 years ago
parent 077ac81688
commit bdaba1d815

@ -268,6 +268,7 @@
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

@ -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");

@ -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 */

@ -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);

Loading…
Cancel
Save