summaryrefslogtreecommitdiff
path: root/lib/fuzzer/afl/afl_driver.cpp
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2018-06-12 15:47:58 +0000
committerDavid Carlier <devnexen@gmail.com>2018-06-12 15:47:58 +0000
commit1226c02661df81f23197eb1c411486816740d30d (patch)
treeca3f90db42c354230f8ac12ae4fd2fee91f1c84c /lib/fuzzer/afl/afl_driver.cpp
parent415baadc64ff31767576da54575260d0e86ca8c6 (diff)
[Fuzzer] Afl driver changing iterations handling
Handling differently the iterations with the type limit and eventually an error message. Reviewers: morehouse, kcc Reviewed By: morehouse Differential Revision: https://reviews.llvm.org/D47880 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@334510 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/fuzzer/afl/afl_driver.cpp')
-rw-r--r--lib/fuzzer/afl/afl_driver.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/fuzzer/afl/afl_driver.cpp b/lib/fuzzer/afl/afl_driver.cpp
index fa494c03b..f3435ffd9 100644
--- a/lib/fuzzer/afl/afl_driver.cpp
+++ b/lib/fuzzer/afl/afl_driver.cpp
@@ -59,6 +59,7 @@ statistics from the file. If that fails then the process will quit.
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
+#include <limits.h>
#include <fstream>
#include <iostream>
@@ -305,6 +306,18 @@ int ExecuteFilesOnyByOne(int argc, char **argv) {
return 0;
}
+static void set_iterations(int *N, const char *arg) {
+ char *next_char;
+ long NL = strtol(arg, &next_char, 10);
+ if (NL < 1 || NL > INT_MAX || *next_char != '\0') {
+ fprintf(stderr, "WARNING: iterations invalid `%s`\n",
+ arg);
+ ::exit(-1);
+ }
+
+ *N = static_cast<int>(NL);
+}
+
int main(int argc, char **argv) {
fprintf(stderr,
"======================= INFO =========================\n"
@@ -331,11 +344,12 @@ int main(int argc, char **argv) {
int N = 1000;
if (argc == 2 && argv[1][0] == '-')
- N = atoi(argv[1] + 1);
- else if(argc == 2 && (N = atoi(argv[1])) > 0)
- fprintf(stderr, "WARNING: using the deprecated call style `%s %d`\n",
- argv[0], N);
- else if (argc > 1)
+ set_iterations(&N, argv[1] + 1);
+ else if(argc == 2) {
+ fprintf(stderr, "WARNING: using the deprecated call style `%s %d`\n",
+ argv[0], N);
+ set_iterations(&N, argv[1]);
+ } else if (argc > 1)
return ExecuteFilesOnyByOne(argc, argv);
assert(N > 0);