Files
systemd/src/fuzz/fuzz.h
T
Zbigniew Jędrzejewski-Szmek 0bb0316f5e Do not use "critical assert_return" in libsystemd or libudev
Previously, when compiled in developer mode, a call into libsystemd with
invalid parameters would result in an abort. This means that it's effectively
impossible to install such libsystemd in a normal system, since various
third-party programs may now abort. A shared library should generally never
abort or exit the calling program.

In python-systemd, the test suite calls into libsystemd, to check if the proper
return values are received and propagated through the Python wrappers.
Obviously with libsystemd compiled from git, the test suite now fails
in a nasty way.

So rework the code to set assert_return_is_critical similarly to how we handle
mempool enablement: the function that returns true is declared as a week
symbol, and we "opt in" by linking a file that provides the function in
libsystemd-shared. Effectively, libsystemd and libudev always have
assert_return_is_critical==false, and our binaries and modules enable it
conditionally.
2025-10-22 10:10:24 +02:00

43 lines
1.2 KiB
C

/* 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"); })