journal: also check that our entry arrays are properly ordered
authorLennart Poettering <lennart@poettering.net>
Wed, 12 Oct 2016 10:12:58 +0000 (12:12 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Oct 2016 18:25:20 +0000 (20:25 +0200)
Let's and extra check, reusing check_properly_ordered() also for
journal_file_next_entry_for_data().

src/journal/journal-file.c

index 52562cd..f598582 100644 (file)
@@ -2583,7 +2583,7 @@ int journal_file_next_entry_for_data(
                 direction_t direction,
                 Object **ret, uint64_t *offset) {
 
-        uint64_t n, i;
+        uint64_t i, n, ofs;
         int r;
         Object *d;
 
@@ -2622,11 +2622,24 @@ int journal_file_next_entry_for_data(
                         return r;
         }
 
-        return generic_array_get_plus_one(f,
-                                          le64toh(d->data.entry_offset),
-                                          le64toh(d->data.entry_array_offset),
-                                          i,
-                                          ret, offset);
+        r = generic_array_get_plus_one(f,
+                                       le64toh(d->data.entry_offset),
+                                       le64toh(d->data.entry_array_offset),
+                                       i,
+                                       ret, &ofs);
+        if (r <= 0)
+                return r;
+
+        /* Ensure our array is properly ordered. */
+        if (p > 0 && check_properly_ordered(ofs, p, direction)) {
+                log_debug("%s data entry array not properly ordered at entry %" PRIu64, f->path, i);
+                return -EBADMSG;
+        }
+
+        if (offset)
+                *offset = ofs;
+
+        return 1;
 }
 
 int journal_file_move_to_entry_by_offset_for_data(