$ dd if=/dev/urandom of=testcase_dir/rand.bin \
bs=`./afl-harness --min-input-size` count=1
+3a. use a tmpfs for findings_dir (Perf improvement and reduced disk load)
+ $ mkdir findings_dir
+ $ mount -t tmpfs -o size=512M tmpfs findings_dir
+
4. run the fuzzer with AFL:
- $ $AFLPATH/afl-fuzz -m none -t 1000 -i testcase_dir -o findings_dir -- \
- ./afl-harness @@
+ $ $AFLPATH/afl-fuzz -t 1000 -i testcase_dir -o findings_dir -- ./afl-harness
Please see AFL documentation for more information.
int main(int argc, char **argv)
{
size_t size;
- FILE *fp;
+ FILE *fp = NULL;
setbuf(stdout, NULL);
break;
case '?':
+ usage:
printf("Usage: %s $FILE | [--min-input-size]\n", argv[0]);
exit(-1);
break;
}
}
- if ( optind != (argc - 1) )
- {
- printf("Expecting only one argument\n");
- exit(-1);
- }
+ if ( optind == argc ) /* No positional parameters. Use stdin. */
+ fp = stdin;
+ else if ( optind != (argc - 1) )
+ goto usage;
- fp = fopen(argv[1], "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);
exit(-1);
}
- fclose(fp);
+ if ( fp != stdin )
+ {
+ fclose(fp);
+ fp = NULL;
+ }
LLVMFuzzerTestOneInput(input, size);