Skip to content

Instantly share code, notes, and snippets.

@pldubouilh
Created April 18, 2020 19:07
Show Gist options
  • Save pldubouilh/42e114a430da25878d6739d11f0c86a5 to your computer and use it in GitHub Desktop.
Save pldubouilh/42e114a430da25878d6739d11f0c86a5 to your computer and use it in GitHub Desktop.
clang fuzzing
#include <stdio.h>
#include <string.h>
// clang -O0 -Wall -g -fsanitize=fuzzer fuzzer.c && ./a.out
int LLVMFuzzerTestOneInput(const char *Data, size_t Size)
{
int maxlen = (int) Size;
const char *start = Data;
char *end, *aaa;
int len;
while (maxlen > 0) {
end = memchr(start, '\0', maxlen);
aaa = memchr(start, 'a', maxlen);
if (aaa == NULL || end == NULL) {
return 1;
}
len = end - aaa;
if (len <= 0) {
return 1;
}
maxlen -= (end - start) + 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment