From 6eab0e45f4777be42a7c269e4cd1e6a5606ac352 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Tue, 26 Mar 2024 18:46:23 +0100
Subject: [PATCH 0477/1160] shared/logs-show: restore infinite loop avoidance
 for corrupted journals

Fixes a bug introduced in e44f06065bf20e8d0e4adacff61350ebd36f299e: it was
supposed to be a refactoring, but unfortunately FOREACH_ARRAY is implemented
using a for loop, so when the 'goto finish' was replaced by 'break', it only
broke the inner loop, leading to a infinite loop.

(cherry picked from commit 1e8c0c671e3076db811804343b3b8d744bcf27ac)
---
 src/shared/logs-show.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index a5d04003bd..0a31be382f 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -2088,7 +2088,7 @@ int journal_get_boots(sd_journal *j, BootId **ret_boots, size_t *ret_n_boots) {
                         if (sd_id128_equal(i->id, boot.id))
                                 /* The boot id is already stored, something wrong with the journal files.
                                  * Exiting as otherwise this problem would cause an infinite loop. */
-                                break;
+                                goto finish;
 
                 if (!GREEDY_REALLOC(boots, n_boots + 1))
                         return -ENOMEM;
@@ -2096,6 +2096,7 @@ int journal_get_boots(sd_journal *j, BootId **ret_boots, size_t *ret_n_boots) {
                 boots[n_boots++] = boot;
         }
 
+ finish:
         *ret_boots = TAKE_PTR(boots);
         *ret_n_boots = n_boots;
         return n_boots > 0;
-- 
2.33.0