dryang / rpms / systemd

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