From: Luca Boccassi Date: Sun, 7 Jun 2026 18:02:38 +0000 (+0100) Subject: journal-importer: cap field size when checking X-Git-Tag: v261-rc4~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d31694318088a908ccbced2fe95ea4657017b47;p=thirdparty%2Fsystemd.git journal-importer: cap field size when checking Originally reported on yeswehack.com as YWH-PGM9780-82 Follow-up for 1e448731f51865184ba988b246d02823a9284d6c --- diff --git a/src/shared/journal-importer.c b/src/shared/journal-importer.c index 87286a33b28..471ad879a4d 100644 --- a/src/shared/journal-importer.c +++ b/src/shared/journal-importer.c @@ -325,7 +325,7 @@ int journal_importer_process_data(JournalImporter *imp) { if (!journal_field_valid(line, sep - line, true)) { char buf[64], *t; - t = strndupa_safe(line, sep - line); + t = strndupa_safe(line, MIN((size_t) (sep - line), sizeof buf)); log_debug("Ignoring invalid field: \"%s\"", cellescape(buf, sizeof buf, t)); @@ -344,7 +344,7 @@ int journal_importer_process_data(JournalImporter *imp) { if (!journal_field_valid(line, n - 1, true)) { char buf[64], *t; - t = strndupa_safe(line, n - 1); + t = strndupa_safe(line, MIN(n - 1, sizeof buf)); log_debug("Ignoring invalid field: \"%s\"", cellescape(buf, sizeof buf, t)); diff --git a/test/units/TEST-04-JOURNAL.journal-remote.sh b/test/units/TEST-04-JOURNAL.journal-remote.sh index 5d4b13d70e0..14be8a13096 100755 --- a/test/units/TEST-04-JOURNAL.journal-remote.sh +++ b/test/units/TEST-04-JOURNAL.journal-remote.sh @@ -310,3 +310,15 @@ systemctl stop systemd-journal-remote.{socket,service} rm -rf /var/log/journal/remote/* rm /run/systemd/journal-upload.conf.d/99-test.conf rm /run/systemd/journal-remote.conf.d/99-test.conf + +DOS_DIR="$(mktemp -d)" +{ head -c $((5 * 1024 * 1024)) /dev/zero | tr '\0' 'A'; printf '\n'; } >"$DOS_DIR/no-separator.export" +{ head -c $((5 * 1024 * 1024)) /dev/zero | tr '\0' 'A'; printf '=value\n'; } >"$DOS_DIR/long-field-name.export" +for export_file in "$DOS_DIR"/no-separator.export "$DOS_DIR"/long-field-name.export; do + rm -f "$DOS_DIR"/*.journal + timeout 30 /usr/lib/systemd/systemd-journal-remote \ + --split-mode=none \ + --output="$DOS_DIR/dos.journal" \ + "$export_file" || [[ $? -lt 124 ]] +done +rm -rf "$DOS_DIR"