sd-journal: do not read unnecessary object
In journal_file_next_entry(), if the passed offset matches an entry object, then generic_array_bisect() returns the object, but the object we requested is the next (or previous) object. Hence, we should not validate the object returned by generic_array_bisect(), otherwise it may fail when the journal is corrupted. Note the validity of the entry object that should be returned by journal_file_next_entry() will be checked in the following generic_array_get(). So, when journal_file_next_entry() succeeds, the returned object is always validated.
This commit is contained in:
@@ -3539,7 +3539,8 @@ int journal_file_next_entry(
|
||||
p,
|
||||
test_object_offset,
|
||||
direction,
|
||||
ret_object ? &o : NULL, &q, &i);
|
||||
NULL, &q, &i); /* Here, do not read entry object, as the result object
|
||||
* may not be the one we want, and it may be broken. */
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
@@ -3549,12 +3550,11 @@ int journal_file_next_entry(
|
||||
* the same offset, and the index needs to be shifted. Otherwise, use the found object as is,
|
||||
* as it is the nearest entry object from the input offset 'p'. */
|
||||
|
||||
if (p != q)
|
||||
goto found;
|
||||
|
||||
r = bump_array_index(&i, direction, n);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
if (p == q) {
|
||||
r = bump_array_index(&i, direction, n);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* And jump to it */
|
||||
r = generic_array_get(f, le64toh(f->header->entry_array_offset), i, direction, ret_object ? &o : NULL, &q);
|
||||
@@ -3566,7 +3566,7 @@ int journal_file_next_entry(
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
|
||||
"%s: entry array not properly ordered at entry index %" PRIu64,
|
||||
f->path, i);
|
||||
found:
|
||||
|
||||
if (ret_object)
|
||||
*ret_object = o;
|
||||
if (ret_offset)
|
||||
|
||||
Reference in New Issue
Block a user