summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2023-04-29 12:01:37 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2023-05-01 10:14:12 +0200
commit0f69a4e9ae2b6916d9da4d47b67ac3e654b9f79e (patch)
treec3e73c7517a820b5e3a725b64fed6593ca9eecaf /test
parentde965f48934325e6fc564720aa318f24c315caec (diff)
downloadsystemd-0f69a4e9ae2b6916d9da4d47b67ac3e654b9f79e.tar.gz
test: test journalctl with corrupted journals
Last month I monkey-patched journald to produce a small (64K) but valid journal and used that as an input to four AFL fuzzers. After a month it generated quite a nice corpora (4738 test cases) and after filtering and minimizing it I was left with 619 unique journals with various levels of corruption that probe the journal code. It seems to detect past issues like systemd#26567, etc.
Diffstat (limited to 'test')
-rw-r--r--test/test-journals/afl-corrupted-journals.tar.zstbin0 -> 94293 bytes
-rwxr-xr-xtest/units/testsuite-04.sh35
2 files changed, 35 insertions, 0 deletions
diff --git a/test/test-journals/afl-corrupted-journals.tar.zst b/test/test-journals/afl-corrupted-journals.tar.zst
new file mode 100644
index 0000000000..8c2d92d3ae
--- /dev/null
+++ b/test/test-journals/afl-corrupted-journals.tar.zst
Binary files differ
diff --git a/test/units/testsuite-04.sh b/test/units/testsuite-04.sh
index 8bab2bf9f1..3a7c0347ae 100755
--- a/test/units/testsuite-04.sh
+++ b/test/units/testsuite-04.sh
@@ -318,4 +318,39 @@ systemctl daemon-reload
systemctl restart systemd-journald.service
journalctl --rotate
+# Corrupted journals
+JOURNAL_DIR="$(mktemp -d)"
+REMOTE_OUT="$(mktemp -d)"
+# tar on C8S doesn't support the --zstd option
+unzstd --stdout "/test-journals/afl-corrupted-journals.tar.zst" | tar -xC "$JOURNAL_DIR/"
+# First, try each of them sequentially. Skip this part when running with plain
+# QEMU, as it is excruciatingly slow
+# Note: we care only about exit code 124 (timeout) and special bash exit codes
+# >124 (like signals)
+if [[ "$(systemd-detect-virt -v)" != "qemu" ]]; then
+ while read -r file; do
+ timeout 10 journalctl -b --file="$file" >/dev/null || [[ $? -lt 124 ]]
+ timeout 10 journalctl -o export --file="$file" >/dev/null || [[ $? -lt 124 ]]
+ if [[ -x /usr/lib/systemd/systemd-journal-remote ]]; then
+ timeout 10 /usr/lib/systemd/systemd-journal-remote \
+ --getter="journalctl -o export --file=$file" \
+ --split-mode=none \
+ --output="$REMOTE_OUT/system.journal" || [[ $? -lt 124 ]]
+ timeout 10 journalctl -b --directory="$REMOTE_OUT" >/dev/null || [[ $? -lt 124 ]]
+ rm -f "$REMOTE_OUT"/*
+ fi
+ done < <(find "$JOURNAL_DIR" -type f)
+fi
+# And now all at once
+timeout 30 journalctl -b --directory="$JOURNAL_DIR" >/dev/null || [[ $? -lt 124 ]]
+timeout 30 journalctl -o export --directory="$JOURNAL_DIR" >/dev/null || [[ $? -lt 124 ]]
+if [[ -x /usr/lib/systemd/systemd-journal-remote ]]; then
+ timeout 30 /usr/lib/systemd/systemd-journal-remote \
+ --getter="journalctl -o export --directory=$JOURNAL_DIR" \
+ --split-mode=none \
+ --output="$REMOTE_OUT/system.journal" || [[ $? -lt 124 ]]
+ timeout 10 journalctl -b --directory="$REMOTE_OUT" >/dev/null || [[ $? -lt 124 ]]
+ rm -f "$REMOTE_OUT"/*
+fi
+
touch /testok