summaryrefslogtreecommitdiff
path: root/src/journal/journal-file.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-10-12 12:12:05 +0200
committerLennart Poettering <lennart@poettering.net>2016-10-12 20:25:20 +0200
commitb6da4ed0450ced53a911d974c8b1da6ad9ff212a (patch)
tree9432a8f6fa6eb655d24640247fc945535eaf27d6 /src/journal/journal-file.c
parentaa598ba5b63b70273d6295fce3cb8c304716a205 (diff)
journal: split out check for properly ordered arrays into its own function
This adds a new call check_properly_ordered(), which we can reuse later, and makes the code a bit more readable.
Diffstat (limited to 'src/journal/journal-file.c')
-rw-r--r--src/journal/journal-file.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 8e47ebb944..52562cd0b8 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -2503,6 +2503,18 @@ static int bump_array_index(uint64_t *i, direction_t direction, uint64_t n) {
return 1;
}
+static bool check_properly_ordered(uint64_t new_offset, uint64_t old_offset, direction_t direction) {
+
+ /* Consider it an error if any of the two offsets is uninitialized */
+ if (old_offset == 0 || new_offset == 0)
+ return false;
+
+ /* If we go down, the new offset must be larger than the old one. */
+ return direction == DIRECTION_DOWN ?
+ new_offset > old_offset :
+ new_offset < old_offset;
+}
+
int journal_file_next_entry(
JournalFile *f,
uint64_t p,
@@ -2552,9 +2564,9 @@ int journal_file_next_entry(
if (r <= 0)
return r;
- if (p > 0 &&
- (direction == DIRECTION_DOWN ? ofs <= p : ofs >= p)) {
- log_debug("%s: entry array corrupted at entry %" PRIu64, f->path, i);
+ /* Ensure our array is properly ordered. */
+ if (p > 0 && !check_properly_ordered(ofs, p, direction)) {
+ log_debug("%s: entry array not properly ordered at entry %" PRIu64, f->path, i);
return -EBADMSG;
}