File: fuzz.h

package info (click to toggle)
systemd 259.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 113,388 kB
  • sloc: ansic: 727,211; xml: 121,125; python: 36,732; sh: 34,990; cpp: 946; makefile: 278; awk: 102; lisp: 13; sed: 1
file content (42 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once

#include <stdio.h>

#include "shared-forward.h"

#include "fileio.h"
#include "log.h"
#include "log-assert-critical.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;
}

static inline void fuzz_setup_logging(void) {
        /* We don't want to fill the logs and slow down stuff when running
         * in a fuzzing mode, so disable most of the logging. */
        log_set_assert_return_is_critical(true);
        log_set_max_level(LOG_CRIT);
        log_setup();
}

/* Force value to not be optimized away. */
#define DO_NOT_OPTIMIZE(value) ({ asm volatile("" : : "g"(value) : "memory"); })