daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
803fb7
From 0c2f52bb9b0bce392f14a38d6477e396d6fc987e Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Fri, 24 Jul 2015 02:00:43 +0200
803fb7
Subject: [PATCH] journal: when verifying journal files, handle empty ones
803fb7
 nicely
803fb7
803fb7
A journal file that carries no objects should be considered valid.
803fb7
803fb7
Cherry-picked from: 8dc37a85255f68d62f7af66696cbf6a66401fb2a
803fb7
Resolves: #1350232
803fb7
---
de8967
 src/journal/journal-verify.c | 37 ++++++++++++++----------------------
803fb7
 1 file changed, 14 insertions(+), 23 deletions(-)
803fb7
803fb7
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
803fb7
index d2d5c400c..53f0550da 100644
803fb7
--- a/src/journal/journal-verify.c
803fb7
+++ b/src/journal/journal-verify.c
803fb7
@@ -885,7 +885,11 @@ int journal_file_verify(
803fb7
          * superficial structure, headers, hashes. */
803fb7
 
803fb7
         p = le64toh(f->header->header_size);
803fb7
-        while (p != 0) {
803fb7
+        for (;;) {
803fb7
+                /* Early exit if there are no objects in the file, at all */
803fb7
+                if (le64toh(f->header->tail_object_offset) == 0)
803fb7
+                        break;
803fb7
+
803fb7
                 if (show_progress)
803fb7
                         draw_progress(scale_progress(0x7FFF, p, le64toh(f->header->tail_object_offset)), &last_usec);
803fb7
 
803fb7
@@ -901,9 +905,6 @@ int journal_file_verify(
803fb7
                         goto fail;
803fb7
                 }
803fb7
 
803fb7
-                if (p == le64toh(f->header->tail_object_offset))
803fb7
-                        found_last = true;
803fb7
-
803fb7
                 n_objects ++;
803fb7
 
803fb7
                 r = journal_file_object_verify(f, p, o);
803fb7
@@ -1148,13 +1149,15 @@ int journal_file_verify(
803fb7
                         n_weird ++;
803fb7
                 }
803fb7
 
803fb7
-                if (p == le64toh(f->header->tail_object_offset))
803fb7
-                        p = 0;
803fb7
-                else
803fb7
-                        p = p + ALIGN64(le64toh(o->object.size));
803fb7
-        }
803fb7
+                if (p == le64toh(f->header->tail_object_offset)) {
803fb7
+                        found_last = true;
803fb7
+                        break;
803fb7
+                }
803fb7
 
803fb7
-        if (!found_last) {
803fb7
+                p = p + ALIGN64(le64toh(o->object.size));
803fb7
+        };
803fb7
+
803fb7
+        if (!found_last && le64toh(f->header->tail_object_offset) != 0) {
803fb7
                 error(le64toh(f->header->tail_object_offset), "tail object pointer dead");
803fb7
                 r = -EBADMSG;
803fb7
                 goto fail;
803fb7
@@ -1200,19 +1203,7 @@ int journal_file_verify(
803fb7
                 goto fail;
803fb7
         }
803fb7
 
803fb7
-        if (n_data_hash_tables != 1) {
803fb7
-                error(0, "missing data hash table");
803fb7
-                r = -EBADMSG;
803fb7
-                goto fail;
803fb7
-        }
803fb7
-
803fb7
-        if (n_field_hash_tables != 1) {
803fb7
-                error(0, "missing field hash table");
803fb7
-                r = -EBADMSG;
803fb7
-                goto fail;
803fb7
-        }
803fb7
-
803fb7
-        if (!found_main_entry_array) {
803fb7
+        if (!found_main_entry_array && le64toh(f->header->entry_array_offset) != 0) {
803fb7
                 error(0, "missing entry array");
803fb7
                 r = -EBADMSG;
803fb7
                 goto fail;