chiark / gitweb /
journal: count number of entry arrays in header
[elogind.git] / src / journal / journal-verify.c
index 7c99d44838b3608c8f80176dd65a050932cf104d..b4e34d18a8f28299cb65e5661f33206cb44c31c2 100644 (file)
@@ -38,7 +38,6 @@
  * - Allow building without libgcrypt
  * - check with sparse
  * - 64bit conversions
- * - verification should use MAP_PRIVATE
  *
  * */
 
@@ -316,6 +315,7 @@ static int verify_data(
         if (r < 0)
                 return r;
 
+        i = 1;
         while (i < n) {
                 uint64_t next, m, j;
 
@@ -610,6 +610,7 @@ int journal_file_verify(JournalFile *f, const char *key) {
         data_fd = mkostemp(data_path, O_CLOEXEC);
         if (data_fd < 0) {
                 log_error("Failed to create data file: %m");
+                r = -errno;
                 goto fail;
         }
         unlink(data_path);
@@ -617,6 +618,7 @@ int journal_file_verify(JournalFile *f, const char *key) {
         entry_fd = mkostemp(entry_path, O_CLOEXEC);
         if (entry_fd < 0) {
                 log_error("Failed to create entry file: %m");
+                r = -errno;
                 goto fail;
         }
         unlink(entry_path);
@@ -624,6 +626,7 @@ int journal_file_verify(JournalFile *f, const char *key) {
         entry_array_fd = mkostemp(entry_array_path, O_CLOEXEC);
         if (entry_array_fd < 0) {
                 log_error("Failed to create entry array file: %m");
+                r = -errno;
                 goto fail;
         }
         unlink(entry_array_path);
@@ -834,6 +837,13 @@ int journal_file_verify(JournalFile *f, const char *key) {
                 goto fail;
         }
 
+        if (JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays) &&
+            n_entry_arrays != le64toh(f->header->n_entry_arrays)) {
+                log_error("Entry array number mismatch");
+                r = -EBADMSG;
+                goto fail;
+        }
+
         if (n_data_hash_tables != 1) {
                 log_error("Missing data hash table");
                 r = -EBADMSG;