fuzz: specify protocol with fuzz target name

cf https://redmine.openinfosecfoundation.org/issues/4125

This allows fuzz_applayerparser_parse to fuzz one specific
app-layer protocol based on the binary name, as is done
with the environment variable FUZZ_APPLAYER
That is if we rename/copy to fuzz_applayerparser_parse_smb,
it will fuzz only SMB protocol
This way, we can easily produce different fuzz targets for
each protocol in oss-fuzz
pull/6040/head
Philippe Antoine 5 years ago committed by Victor Julien
parent 6da9a37285
commit e9b76a0e66

@ -15,6 +15,7 @@
#define HEADER_LEN 6
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
int LLVMFuzzerInitialize(int *argc, char ***argv);
AppLayerParserThreadCtx *alp_tctx = NULL;
@ -34,6 +35,30 @@ const uint8_t separator[] = {0x01, 0xD5, 0xCA, 0x7A};
SCInstance surifuzz;
uint64_t forceLayer = 0;
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
char *target_suffix = strrchr((*argv)[0], '_');
if (target_suffix != NULL) {
AppProto applayer = StringToAppProto(target_suffix + 1);
if (applayer != ALPROTO_UNKNOWN) {
forceLayer = applayer;
printf("Forcing %s=%" PRIu64 "\n", AppProtoToString(forceLayer), forceLayer);
return 0;
}
}
// else
const char *forceLayerStr = getenv("FUZZ_APPLAYER");
if (forceLayerStr) {
if (ByteExtractStringUint64(&forceLayer, 10, 0, forceLayerStr) < 0) {
forceLayer = 0;
printf("Invalid numeric value for FUZZ_APPLAYER environment variable");
} else {
printf("Forcing %s\n", AppProtoToString(forceLayer));
}
}
return 0;
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
Flow * f;
@ -67,15 +92,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
PostConfLoadedSetup(&surifuzz);
alp_tctx = AppLayerParserThreadCtxAlloc();
const char* forceLayerStr = getenv("FUZZ_APPLAYER");
if (forceLayerStr) {
if (ByteExtractStringUint64(&forceLayer, 10, 0, forceLayerStr) < 0) {
forceLayer = 0;
printf("Invalid numeric value for FUZZ_APPLAYER environment variable");
} else {
printf("Forcing %s\n", AppProtoToString(forceLayer));
}
}
}
if (data[0] >= ALPROTO_MAX) {

Loading…
Cancel
Save