Skip to content

Instantly share code, notes, and snippets.

@hartwork
Last active February 11, 2025 12:20
Show Gist options
  • Save hartwork/3e5fa6215fc0eed35ddf52658aaeb5b0 to your computer and use it in GitHub Desktop.
Save hartwork/3e5fa6215fc0eed35ddf52658aaeb5b0 to your computer and use it in GitHub Desktop.
libFuzzer fuzzer that dumps its input to stdout to get a sense of the effect of a given dictionary file (fuzzer argument "-dict=FILE")
// Copyright (c) 2025 Sebastian Pipping <[email protected]>
// Licensed under the MIT license
#include <cctype> // isprint(3)
#include <cstdint>
#include <cstdio> // putchar(3), printf(3)
#include <sys/param.h> // MIN(3)
static const unsigned int MAX_LEN = 30;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
printf("[%19zd] \"", Size);
for (size_t i = 0; i < MIN(Size, MAX_LEN); i++) {
const uint8_t ch = Data[i];
switch (ch) {
case '\0':
printf("\\0");
break;
case '"':
printf("\\\"");
break;
case '\\':
printf("\\\\");
break;
default:
if (isprint(ch)) {
putchar(ch);
} else {
printf("\\x%X", ch);
}
}
}
printf("\"");
if (Size > MAX_LEN) {
printf(" [..]");
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment