summaryrefslogtreecommitdiffstats
path: root/src/fuzz
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2023-10-18 23:11:13 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-10-19 11:05:20 +0200
commit4820c9d41748640ce6a29fc76d6463c822a31662 (patch)
tree073c65a8e74eaede325f46b32b9615886e0425ae /src/fuzz
parentMerge pull request #29611 from mrc0mmand/execute-serialize-fuzz (diff)
downloadsystemd-4820c9d41748640ce6a29fc76d6463c822a31662.tar.xz
systemd-4820c9d41748640ce6a29fc76d6463c822a31662.zip
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
Diffstat (limited to 'src/fuzz')
-rw-r--r--src/fuzz/fuzz-bootspec.c4
-rw-r--r--src/fuzz/fuzz-bus-label.c2
-rw-r--r--src/fuzz/fuzz-calendarspec.c3
-rw-r--r--src/fuzz/fuzz-catalog.c3
-rw-r--r--src/fuzz/fuzz-compress.c5
-rw-r--r--src/fuzz/fuzz-env-file.c5
-rw-r--r--src/fuzz/fuzz-hostname-setup.c5
-rw-r--r--src/fuzz/fuzz-json.c4
-rw-r--r--src/fuzz/fuzz-time-util.c3
-rw-r--r--src/fuzz/fuzz-udev-database.c3
-rw-r--r--src/fuzz/fuzz-varlink-idl.c4
-rw-r--r--src/fuzz/fuzz-varlink.c3
-rw-r--r--src/fuzz/fuzz.h8
13 files changed, 21 insertions, 31 deletions
diff --git a/src/fuzz/fuzz-bootspec.c b/src/fuzz/fuzz-bootspec.c
index cea674c4c8..7a85787764 100644
--- a/src/fuzz/fuzz-bootspec.c
+++ b/src/fuzz/fuzz-bootspec.c
@@ -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));
diff --git a/src/fuzz/fuzz-bus-label.c b/src/fuzz/fuzz-bus-label.c
index 93bac9adf4..c7be82a767 100644
--- a/src/fuzz/fuzz-bus-label.c
+++ b/src/fuzz/fuzz-bus-label.c
@@ -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);
diff --git a/src/fuzz/fuzz-calendarspec.c b/src/fuzz/fuzz-calendarspec.c
index 573a48a48b..b31a3f2b17 100644
--- a/src/fuzz/fuzz-calendarspec.c
+++ b/src/fuzz/fuzz-calendarspec.c
@@ -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));
diff --git a/src/fuzz/fuzz-catalog.c b/src/fuzz/fuzz-catalog.c
index f3029f49d0..f9561f24c4 100644
--- a/src/fuzz/fuzz-catalog.c
+++ b/src/fuzz/fuzz-catalog.c
@@ -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));
diff --git a/src/fuzz/fuzz-compress.c b/src/fuzz/fuzz-compress.c
index 9cd571dfb8..c3f68f62dd 100644
--- a/src/fuzz/fuzz-compress.c
+++ b/src/fuzz/fuzz-compress.c
@@ -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),
diff --git a/src/fuzz/fuzz-env-file.c b/src/fuzz/fuzz-env-file.c
index 6217361b2e..ff7e529ac3 100644
--- a/src/fuzz/fuzz-env-file.c
+++ b/src/fuzz/fuzz-env-file.c
@@ -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);
diff --git a/src/fuzz/fuzz-hostname-setup.c b/src/fuzz/fuzz-hostname-setup.c
index d7c23eef12..4895631b67 100644
--- a/src/fuzz/fuzz-hostname-setup.c
+++ b/src/fuzz/fuzz-hostname-setup.c
@@ -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);
diff --git a/src/fuzz/fuzz-json.c b/src/fuzz/fuzz-json.c
index c83ec83328..3d6d689f28 100644
--- a/src/fuzz/fuzz-json.c
+++ b/src/fuzz/fuzz-json.c
@@ -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);
diff --git a/src/fuzz/fuzz-time-util.c b/src/fuzz/fuzz-time-util.c
index 8e6cb8553b..5be2e4f1dd 100644
--- a/src/fuzz/fuzz-time-util.c
+++ b/src/fuzz/fuzz-time-util.c
@@ -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));
diff --git a/src/fuzz/fuzz-udev-database.c b/src/fuzz/fuzz-udev-database.c
index 2a48c14961..6b4fc8270d 100644
--- a/src/fuzz/fuzz-udev-database.c
+++ b/src/fuzz/fuzz-udev-database.c
@@ -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)
diff --git a/src/fuzz/fuzz-varlink-idl.c b/src/fuzz/fuzz-varlink-idl.c
index cefc49219c..7ad0f28413 100644
--- a/src/fuzz/fuzz-varlink-idl.c
+++ b/src/fuzz/fuzz-varlink-idl.c
@@ -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));
diff --git a/src/fuzz/fuzz-varlink.c b/src/fuzz/fuzz-varlink.c
index cbfde088d9..3407760fbf 100644
--- a/src/fuzz/fuzz-varlink.c
+++ b/src/fuzz/fuzz-varlink.c
@@ -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"));
diff --git a/src/fuzz/fuzz.h b/src/fuzz/fuzz.h
index 77e0ad98dc..698ba42d2f 100644
--- a/src/fuzz/fuzz.h
+++ b/src/fuzz/fuzz.h
@@ -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"); })