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