AFL Code/libFuzzer Code quick copy
int main(int argc, char** argv) { if(argc>1){ FILE *f = fopen(argv[1], "rb"); fseek(f, 0, SEEK_END); size_t fsize = ftell(f); rewind(f); uint8_t* str = (uint8_t *)malloc(fsize + 1); memset(str, 0, fsize + 1); fread((void*)str, fsize, 1, f); fclose(f); LLVMFuzzerTestOneInput(str, fsize + 1); free(str); str = (uint8_t*)0; } else { uint8_t* str = (uint8_t *)malloc(4096); memset(str, 0, 4096); fgets((char*)str, 4095, stdin); LLVMFuzzerTestOneInput(str, 4096); free(str); str = (uint8_t*)0; } return 0; } =========== clang++ -g -fsanitize=fuzzer,address,undefined -fsanitize-coverage=trace-pc-guard FTS/tutorial/fuzz_me.cc libFuzzer.a extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { DoSomethingWithData(data, size); return 0; }
Friday, March 22, 2019 by blast