diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-05-12 12:51:11 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-05-12 14:57:07 +0200 |
commit | c4f883b78e5ffd326a82eaf18e01a9e4e243db58 (patch) | |
tree | 712faa735096321206f0afd6097a4dd09bfcd6c1 /src/fuzz | |
parent | 7593691aadc7e1e9c5f17fd26424abe337d56302 (diff) | |
download | systemd-c4f883b78e5ffd326a82eaf18e01a9e4e243db58.tar.gz |
fuzzers: ignore size limits when compiled standalone
This way we can still call fuzzers on old samples, but oss-fuzz will not waste
its and our time finding overly large inputs.
Diffstat (limited to 'src/fuzz')
-rw-r--r-- | src/fuzz/fuzz-bootspec.c | 2 | ||||
-rw-r--r-- | src/fuzz/fuzz-env-file.c | 2 | ||||
-rw-r--r-- | src/fuzz/fuzz.h | 12 |
3 files changed, 14 insertions, 2 deletions
diff --git a/src/fuzz/fuzz-bootspec.c b/src/fuzz/fuzz-bootspec.c index 0594a0dea5..c26cc94db9 100644 --- a/src/fuzz/fuzz-bootspec.c +++ b/src/fuzz/fuzz-bootspec.c @@ -84,7 +84,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { _cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL; int r; - if (size > 65536) + if (outside_size_range(size, 0, 65536)) return 0; /* Disable most logging if not running standalone */ diff --git a/src/fuzz/fuzz-env-file.c b/src/fuzz/fuzz-env-file.c index 431f172306..6217361b2e 100644 --- a/src/fuzz/fuzz-env-file.c +++ b/src/fuzz/fuzz-env-file.c @@ -12,7 +12,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { _cleanup_fclose_ FILE *f = NULL; _cleanup_strv_free_ char **rl = NULL, **rlp = NULL; - if (size > 65536) + if (outside_size_range(size, 0, 65536)) return 0; f = data_to_file(data, size); diff --git a/src/fuzz/fuzz.h b/src/fuzz/fuzz.h index d7cbb0bb16..04c438edaf 100644 --- a/src/fuzz/fuzz.h +++ b/src/fuzz/fuzz.h @@ -4,6 +4,7 @@ #include <stddef.h> #include <stdint.h> +#include "env-util.h" #include "fileio.h" /* The entry point into the fuzzer */ @@ -15,3 +16,14 @@ static inline FILE* data_to_file(const uint8_t *data, size_t size) { else return fmemopen_unlocked((char*) data, size, "re"); } + +/* Check if we are within the specified size range. + * The upper limit is ignored if FUZZ_USE_SIZE_LIMIT is unset. + */ +static inline bool outside_size_range(size_t size, size_t lower, size_t upper) { + if (size < lower) + return true; + if (size > upper) + return FUZZ_USE_SIZE_LIMIT; + return false; +} |