diff options
author | Janne Grunau <janne-vlc@jannau.net> | 2020-09-17 22:01:50 +0300 |
---|---|---|
committer | Jean-Baptiste Kempf <jb@videolan.org> | 2020-09-27 16:38:45 +0300 |
commit | ac1cb28d1e66ff03eedb495cded1f6ac3dcce07f (patch) | |
tree | dc0e62b6c5ae939f2e296d27a3f8378904f412ce /tests/libfuzzer | |
parent | 2c09aaa4d7e0f96ca5a4cdefb6a04d0cf7e0bf4b (diff) |
fuzzer: parse '--cpumask X' command line argument
Diffstat (limited to 'tests/libfuzzer')
-rw-r--r-- | tests/libfuzzer/dav1d_fuzzer.c | 36 | ||||
-rw-r--r-- | tests/libfuzzer/dav1d_fuzzer.h | 1 | ||||
-rw-r--r-- | tests/libfuzzer/main.c | 6 |
3 files changed, 40 insertions, 3 deletions
diff --git a/tests/libfuzzer/dav1d_fuzzer.c b/tests/libfuzzer/dav1d_fuzzer.c index 4506d2f..bd040a8 100644 --- a/tests/libfuzzer/dav1d_fuzzer.c +++ b/tests/libfuzzer/dav1d_fuzzer.c @@ -31,6 +31,7 @@ #include <stddef.h> #include <stdint.h> #include <string.h> +#include <stdlib.h> #include <dav1d/dav1d.h> #include "src/cpu.h" @@ -38,8 +39,6 @@ #ifdef DAV1D_ALLOC_FAIL -#include <stdlib.h> - #include "alloc_fail.h" static unsigned djb_xor(const uint8_t * c, size_t len) { @@ -56,6 +55,39 @@ static unsigned r32le(const uint8_t *const p) { #define DAV1D_FUZZ_MAX_SIZE 4096 * 4096 +// search for "--cpumask xxx" in argv and remove both parameters +int LLVMFuzzerInitialize(int *argc, char ***argv) { + int i = 1; + for (; i < *argc; i++) { + if (!strcmp((*argv)[i], "--cpumask")) { + const char * cpumask = (*argv)[i+1]; + if (cpumask) { + char *end; + unsigned res; + if (!strncmp(cpumask, "0x", 2)) { + cpumask += 2; + res = (unsigned) strtoul(cpumask, &end, 16); + } else { + res = (unsigned) strtoul(cpumask, &end, 0); + } + if (end != cpumask && !end[0]) { + dav1d_set_cpu_flags_mask(res); + } + } + break; + } + } + + for (; i < *argc - 2; i++) { + (*argv)[i] = (*argv)[i + 2]; + } + + *argc = i; + + return 0; +} + + // expects ivf input int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/tests/libfuzzer/dav1d_fuzzer.h b/tests/libfuzzer/dav1d_fuzzer.h index 5d93299..0cbbad4 100644 --- a/tests/libfuzzer/dav1d_fuzzer.h +++ b/tests/libfuzzer/dav1d_fuzzer.h @@ -31,6 +31,7 @@ #include <stddef.h> #include <stdint.h> +int LLVMFuzzerInitialize(int *argc, char ***argv); int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); #endif /* DAV1D_TESTS_LIBFUZZER_DAV1D_FUZZER_H */ diff --git a/tests/libfuzzer/main.c b/tests/libfuzzer/main.c index 985ebba..8647738 100644 --- a/tests/libfuzzer/main.c +++ b/tests/libfuzzer/main.c @@ -40,7 +40,7 @@ // expects ivf input -int main(const int argc, char *const *const argv) { +int main(int argc, char *argv[]) { int ret = -1; FILE *f = NULL; int64_t fsize; @@ -48,6 +48,10 @@ int main(const int argc, char *const *const argv) { uint8_t *data = NULL; size_t size = 0; + if (LLVMFuzzerInitialize(&argc, &argv)) { + return 1; + } + if (argc != 2) { fprintf(stdout, "Usage:\n%s fuzzing_testcase.ivf\n", argv[0]); return -1; |