1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stddef.h>
5 #include <stdint.h>
6
7 #include "env-util.h"
8 #include "fileio.h"
9
10 /* The entry point into the fuzzer */
11 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
12
data_to_file(const uint8_t * data,size_t size)13 static inline FILE* data_to_file(const uint8_t *data, size_t size) {
14 if (size == 0)
15 return fopen("/dev/null", "re");
16 else
17 return fmemopen_unlocked((char*) data, size, "re");
18 }
19
20 /* Check if we are within the specified size range.
21 * The upper limit is ignored if FUZZ_USE_SIZE_LIMIT is unset.
22 */
outside_size_range(size_t size,size_t lower,size_t upper)23 static inline bool outside_size_range(size_t size, size_t lower, size_t upper) {
24 if (size < lower)
25 return true;
26 if (size > upper)
27 return FUZZ_USE_SIZE_LIMIT;
28 return false;
29 }
30