|
Zbigniew Jędrzejewski-Szmek |
96237b |
From c77f203a510d27ab08729454bc865547c6111d02 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
Date: Thu, 27 Feb 2014 00:07:29 -0500
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
Subject: [PATCH] journal: assume that next entry is after previous entry
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
With a corrupted file, we can get in a situation where two entries
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
in the entry array point to the same object. Then journal_file_next_entry
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
will find the first one using generic_arrray_bisect, and try to move to
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
the second one, but since the address is the same, generic_array_get will
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
return the first one. journal_file_next_entry ends up in an infinite loop.
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
https://bugzilla.redhat.com/show_bug.cgi?id=1047039
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
(cherry picked from commit fb099c8d2af6620db2709e826a258089d10cdfe8)
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
---
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
src/journal/journal-file.c | 26 ++++++++++++++++++++------
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
1 file changed, 20 insertions(+), 6 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
index 23c4d28..c27289c 100644
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
--- a/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+++ b/src/journal/journal-file.c
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
@@ -1359,7 +1359,7 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
}
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
typedef struct ChainCacheItem {
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
- uint64_t first; /* the array at the begin of the chain */
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ uint64_t first; /* the array at the beginning of the chain */
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
uint64_t array; /* the cached array */
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
uint64_t begin; /* the first item in the cached array */
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
uint64_t total; /* the total number of items in all arrays before this one in the chain */
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
@@ -1945,7 +1945,7 @@ int journal_file_next_entry(
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
direction_t direction,
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
Object **ret, uint64_t *offset) {
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
- uint64_t i, n;
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ uint64_t i, n, ofs;
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
assert(f);
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
@@ -1986,10 +1986,24 @@ int journal_file_next_entry(
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
}
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
/* And jump to it */
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
- return generic_array_get(f,
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
- le64toh(f->header->entry_array_offset),
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
- i,
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
- ret, offset);
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ r = generic_array_get(f,
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ le64toh(f->header->entry_array_offset),
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ i,
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ ret, &ofs;;
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ if (r <= 0)
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ if (p > 0 &&
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ (direction == DIRECTION_DOWN ? ofs <= p : ofs >= p)) {
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ log_debug("%s: entry array corrupted at entry %"PRIu64,
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ f->path, i);
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ return -EBADMSG;
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ if (offset)
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ *offset = ofs;
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
+ return 1;
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
}
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
|
|
Zbigniew Jędrzejewski-Szmek |
96237b |
int journal_file_skip_entry(
|