From 905553acb1b604377ebc50010336a365f2553e1a Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 26 Apr 2023 20:37:00 +0900
Subject: [PATCH] sd-journal: copy boot ID

The pointer to boot ID may be invalidate by journal_file_move_to_object()
calls in the later loop.

(cherry picked from commit bf9b7728e6e8eb185d2c9bfc6641077489384bc8)
(cherry picked from commit 3bc2553cfcc57144aadacff0555b1a0e45e3fdbf)
(cherry picked from commit 2a4dca19f1667f9ae7d273d552e0247d3e405c62)

Conflict:code context adaptation
Reference:https://github.com/systemd/systemd-stable/commit/905553acb1b604377ebc50010336a365f2553e1a
---
 src/libsystemd/sd-journal/journal-file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c
index 204debed64..6561b12aca 100644
--- a/src/libsystemd/sd-journal/journal-file.c
+++ b/src/libsystemd/sd-journal/journal-file.c
@@ -3737,7 +3737,7 @@ int journal_file_dispose(int dir_fd, const char *fname) {
 
 int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint64_t p) {
         uint64_t n, m = 0, xor_hash = 0;
-        const sd_id128_t *boot_id;
+        sd_id128_t boot_id;
         dual_timestamp ts;
         EntryItem *items;
         int r;
@@ -3754,7 +3754,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
 
         ts.monotonic = le64toh(o->entry.monotonic);
         ts.realtime = le64toh(o->entry.realtime);
-        boot_id = &o->entry.boot_id;
+        boot_id = o->entry.boot_id;
 
         n = journal_file_entry_n_items(o);
         /* alloca() can't take 0, hence let's allocate at least one */
@@ -3831,8 +3831,8 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6
         if (m == 0)
                 return 0;
 
-        r = journal_file_append_entry_internal(to, &ts, boot_id, xor_hash, items, m,
-                                               NULL, NULL, NULL);
+        r = journal_file_append_entry_internal(to, &ts, &boot_id, xor_hash, items, m,
+                                               NULL, NULL, NULL);
 
         if (mmap_cache_got_sigbus(to->mmap, to->cache_fd))
                 return -EIO;
-- 
2.33.0

