Files
systemd/src/fuzz/fuzz.h
T
Zbigniew Jędrzejewski-Szmek f3bd4b3df5 tree-wide: do not use "re" with fmemopen
The man page says nothing about "e". Glibc clearly accepts it without fuss, but
it is meaningless for a memory object (and probably doesn't work). This use is
not portable, so let's avoid it.
2022-10-19 10:10:57 +02:00

33 lines
947 B
C

/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stddef.h>
#include <stdint.h>
#include "env-util.h"
#include "fileio.h"
/* The entry point into the fuzzer */
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
static inline FILE* data_to_file(const uint8_t *data, size_t size) {
if (size == 0)
return fopen("/dev/null", "re");
else
return fmemopen_unlocked((char*) data, size, "r");
}
/* 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;
}
/* Force value to not be optimized away. */
#define DO_NOT_OPTIMIZE(value) ({ asm volatile("" : : "g"(value) : "memory"); })