2. run the following commands to build:
$ cd tools/fuzz/x86_instruction_emulator
$ make distclean
- $ make CC=$AFLPATH/afl-gcc afl # produces afl-harness
+
+ If you have a new enough version of Clang/LLVM and have configured AFL's
+ llvm_mode, make use of afl-clang-fast:
+
+ $ make CC=$AFLPATH/afl-clang-fast afl # produces afl-harness
+
+ If not, use the default afl-gcc:
+
+ $ make CC=$AFLPATH/afl-gcc afl # produces afl-harness
3. provide initial test case (fuzzer dependent, see afl-*.c):
$ mkdir testcase_dir
size_t size;
FILE *fp = NULL;
+ setbuf(stdin, NULL);
setbuf(stdout, NULL);
while ( 1 )
if ( LLVMFuzzerInitialize(&argc, &argv) )
exit(-1);
- if ( fp != stdin ) /* If not using stdin, open the provided file. */
+#ifdef __AFL_HAVE_MANUAL_CONTROL
+ __AFL_INIT();
+
+ while ( __AFL_LOOP(1000) )
+#endif
{
- fp = fopen(argv[optind], "rb");
- if ( fp == NULL )
+ if ( fp != stdin ) /* If not using stdin, open the provided file. */
{
- perror("fopen");
- exit(-1);
+ fp = fopen(argv[optind], "rb");
+ if ( fp == NULL )
+ {
+ perror("fopen");
+ exit(-1);
+ }
}
- }
- size = fread(input, 1, INPUT_SIZE, fp);
+ size = fread(input, 1, INPUT_SIZE, fp);
- if ( ferror(fp) )
- {
- perror("fread");
- exit(-1);
- }
+ if ( ferror(fp) )
+ {
+ perror("fread");
+ exit(-1);
+ }
- if ( !feof(fp) )
- {
- printf("Input too large\n");
- exit(-1);
- }
+ if ( !feof(fp) )
+ {
+ printf("Input too large\n");
+ exit(-1);
+ }
- if ( fp != stdin )
- {
- fclose(fp);
- fp = NULL;
- }
+ if ( fp != stdin )
+ {
+ fclose(fp);
+ fp = NULL;
+ }
- LLVMFuzzerTestOneInput(input, size);
+ LLVMFuzzerTestOneInput(input, size);
+ }
return 0;
}