sd-journal: make bump_entry_array() return positive when a valid offset found
When it returns 0 offset, then the subsequent journal_file_move_to_object() will fail. Let's return generic_array_get() earlier in such situation.
This commit is contained in:
@@ -2698,47 +2698,48 @@ static int bump_array_index(uint64_t *i, direction_t direction, uint64_t n) {
|
||||
|
||||
static int bump_entry_array(
|
||||
JournalFile *f,
|
||||
Object *o,
|
||||
uint64_t offset,
|
||||
uint64_t first,
|
||||
Object *o, /* the current entry array object. */
|
||||
uint64_t offset, /* the offset of the entry array object. */
|
||||
uint64_t first, /* The offset of the first entry array object in the chain. */
|
||||
direction_t direction,
|
||||
uint64_t *ret) {
|
||||
|
||||
uint64_t p, q = 0;
|
||||
int r;
|
||||
|
||||
assert(f);
|
||||
assert(offset);
|
||||
assert(ret);
|
||||
|
||||
if (direction == DIRECTION_DOWN) {
|
||||
assert(o);
|
||||
assert(o->object.type == OBJECT_ENTRY_ARRAY);
|
||||
|
||||
*ret = le64toh(o->entry_array.next_entry_array_offset);
|
||||
return 0;
|
||||
} else {
|
||||
|
||||
/* Entry array chains are a singly linked list, so to find the previous array in the chain, we have
|
||||
* to start iterating from the top. */
|
||||
|
||||
assert(offset > 0);
|
||||
|
||||
uint64_t p = first, q = 0;
|
||||
while (p > 0 && p != offset) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY_ARRAY, p, &o);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
q = p;
|
||||
p = le64toh(o->entry_array.next_entry_array_offset);
|
||||
}
|
||||
|
||||
/* If we can't find the previous entry array in the entry array chain, we're likely dealing with a
|
||||
* corrupted journal file. */
|
||||
if (p == 0)
|
||||
return -EBADMSG;
|
||||
|
||||
*ret = q;
|
||||
}
|
||||
|
||||
/* Entry array chains are a singly linked list, so to find the previous array in the chain, we have
|
||||
* to start iterating from the top. */
|
||||
|
||||
p = first;
|
||||
|
||||
while (p > 0 && p != offset) {
|
||||
r = journal_file_move_to_object(f, OBJECT_ENTRY_ARRAY, p, &o);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
q = p;
|
||||
p = le64toh(o->entry_array.next_entry_array_offset);
|
||||
}
|
||||
|
||||
/* If we can't find the previous entry array in the entry array chain, we're likely dealing with a
|
||||
* corrupted journal file. */
|
||||
if (p == 0)
|
||||
return -EBADMSG;
|
||||
|
||||
*ret = q;
|
||||
|
||||
return 0;
|
||||
return *ret > 0;
|
||||
}
|
||||
|
||||
static int generic_array_get(
|
||||
@@ -2781,7 +2782,7 @@ static int generic_array_get(
|
||||
* array and start iterating entries from there. */
|
||||
|
||||
r = bump_entry_array(f, NULL, a, first, DIRECTION_UP, &a);
|
||||
if (r < 0)
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
i = UINT64_MAX;
|
||||
@@ -2843,7 +2844,7 @@ static int generic_array_get(
|
||||
} while (bump_array_index(&i, direction, k) > 0);
|
||||
|
||||
r = bump_entry_array(f, o, a, first, direction, &a);
|
||||
if (r < 0)
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
t += k;
|
||||
|
||||
Reference in New Issue
Block a user