fuzz: unify logging setup
Make sure we don't log anything when running in "fuzzing" mode. Also, when at it, unify the setup logic into a helper, pretty similar to the test_setup_logging() one. Addresses: - https://github.com/systemd/systemd/pull/29558#pullrequestreview-1676060607 - https://github.com/systemd/systemd/pull/29558#discussion_r1358940663
This commit is contained in:
committed by
Luca Boccassi
parent
47174dc054
commit
4820c9d417
@@ -87,9 +87,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
if (outside_size_range(size, 0, 65536))
|
||||
return 0;
|
||||
|
||||
/* Disable most logging if not running standalone */
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
assert_se(datadup = memdup_suffix0(data, size));
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_free_ char *unescaped = NULL, *escaped = NULL;
|
||||
|
||||
fuzz_setup_logging();
|
||||
|
||||
unescaped = bus_label_unescape_n((const char*)data, size);
|
||||
assert_se(unescaped != NULL);
|
||||
escaped = bus_label_escape(unescaped);
|
||||
|
||||
@@ -12,8 +12,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
int r;
|
||||
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
assert_se(str = memdup_suffix0(data, size));
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
_cleanup_ordered_hashmap_free_free_free_ OrderedHashmap *h = NULL;
|
||||
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
assert_se(h = ordered_hashmap_new(&catalog_hash_ops));
|
||||
|
||||
|
||||
@@ -29,10 +29,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
|
||||
int alg = h->alg;
|
||||
|
||||
/* We don't want to fill the logs with messages about parse errors.
|
||||
* Disable most logging if not running standalone */
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
log_info("Using compression %s, data size=%zu",
|
||||
compression_to_string(alg),
|
||||
|
||||
@@ -18,10 +18,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
f = data_to_file(data, size);
|
||||
assert_se(f);
|
||||
|
||||
/* We don't want to fill the logs with messages about parse errors.
|
||||
* Disable most logging if not running standalone */
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
(void) load_env_file(f, NULL, &rl);
|
||||
assert_se(fseek(f, 0, SEEK_SET) == 0);
|
||||
|
||||
@@ -12,10 +12,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
f = data_to_file(data, size);
|
||||
assert_se(f);
|
||||
|
||||
/* We don't want to fill the logs with messages about parse errors.
|
||||
* Disable most logging if not running standalone */
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
(void) read_etc_hostname_stream(f, &ret);
|
||||
|
||||
|
||||
@@ -14,9 +14,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
FILE *g = NULL;
|
||||
int r;
|
||||
|
||||
/* Disable most logging if not running standalone */
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
f = data_to_file(data, size);
|
||||
assert_se(f);
|
||||
|
||||
@@ -9,8 +9,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
usec_t usec;
|
||||
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
assert_se(str = memdup_suffix0(data, size));
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_(unlink_tempfilep) char filename[] = "/tmp/fuzz-udev-database.XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
if (!getenv("SYSTEMD_LOG_LEVEL"))
|
||||
log_set_max_level(LOG_CRIT);
|
||||
fuzz_setup_logging();
|
||||
|
||||
assert_se(fmkostemp_safe(filename, "r+", &f) == 0);
|
||||
if (size != 0)
|
||||
|
||||
@@ -14,9 +14,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_free_ char *str = NULL, *dump = NULL;
|
||||
int r;
|
||||
|
||||
log_set_max_level(LOG_CRIT);
|
||||
log_parse_environment();
|
||||
(void) log_open();
|
||||
fuzz_setup_logging();
|
||||
|
||||
assert_se(str = memdup_suffix0(data, size));
|
||||
|
||||
|
||||
@@ -92,8 +92,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_(varlink_flush_close_unrefp) Varlink *c = NULL;
|
||||
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||
|
||||
log_set_max_level(LOG_CRIT);
|
||||
log_parse_environment();
|
||||
fuzz_setup_logging();
|
||||
|
||||
assert_se(null = fopen("/dev/null", "we"));
|
||||
|
||||
|
||||
@@ -28,5 +28,13 @@ static inline bool outside_size_range(size_t size, size_t lower, size_t upper) {
|
||||
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_max_level(LOG_CRIT);
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
}
|
||||
|
||||
/* Force value to not be optimized away. */
|
||||
#define DO_NOT_OPTIMIZE(value) ({ asm volatile("" : : "g"(value) : "memory"); })
|
||||
|
||||
Reference in New Issue
Block a user