]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/logs-show: restore infinite loop avoidance for corrupted journals
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 26 Mar 2024 17:46:23 +0000 (18:46 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 27 Mar 2024 01:16:16 +0000 (10:16 +0900)
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.

src/shared/logs-show.c

index 3b6988b0182e8c4af8b8e482bf770794f922a48a..85dd3db278958054f653127e59fbd7d341e08108 100644 (file)
@@ -2056,7 +2056,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;
@@ -2064,6 +2064,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;