If journal_file_data_payload() returns -EBADMSG or -EADDRNOTAVAIL,
we skip the entry and go to the next entry, but we never modify
the number of items that we pass to journal_file_append_entry_internal()
if that happens, which means we could try to append garbage to the
journal file.
Let's keep track of the number of fields we've appended to avoid this
problem.
_cleanup_free_ EntryItem *items_alloc = NULL;
EntryItem *items;
- uint64_t q, n, xor_hash = 0;
+ uint64_t q, n, m = 0, xor_hash = 0;
const sd_id128_t *boot_id;
dual_timestamp ts;
int r;
else
xor_hash ^= le64toh(u->data.hash);
- items[i] = (EntryItem) {
+ items[m++] = (EntryItem) {
.object_offset = h,
.hash = le64toh(u->data.hash),
};
return r;
}
+ if (m == 0)
+ return 0;
+
r = journal_file_append_entry_internal(
to,
&ts,
&from->header->machine_id,
xor_hash,
items,
- n,
+ m,
seqnum,
seqnum_id,
/* ret_object= */ NULL,