1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

journal-file: refuse writing to journal files where the header size is different then expected

We keep adding fields to the header, and it's fine reading files with
different header sizes, as we check via the size if the fields we need
are included. However, let's be stricter when writing journal files than
when reading, and insist that the header structure in the file actually
matches our expectations. Refuse otherwise, so that a new file is
created after rotation that then matches our expectations.

This makes sure that mismatch in header size is treated exactly as
unknown "compatible" flags, which is our other mechanism to allow
extending the journal file format in a non-breaking way.
This commit is contained in:
Lennart Poettering 2023-01-31 23:00:07 +01:00 committed by Daan De Meyer
parent 1bb6ba08b1
commit 75bf2627b0

View File

@ -483,6 +483,11 @@ static int journal_file_verify_header(JournalFile *f) {
if (header_size < HEADER_SIZE_MIN)
return -EBADMSG;
/* When open for writing we refuse to open files with a mismatch of the header size, i.e. writing to
* files implementing older or new header structures. */
if (journal_file_writable(f) && header_size != sizeof(Header))
return -EPROTONOSUPPORT;
if (JOURNAL_HEADER_SEALED(f->header) && !JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays))
return -EBADMSG;