]> git.ipfire.org Git - thirdparty/systemd.git/commit
sd-journal: fix corrupted journal handling of generic_array_bisect()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 27 Nov 2023 02:55:49 +0000 (11:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 1 Dec 2023 00:56:10 +0000 (09:56 +0900)
commita93be359aef53b62aa90dd49640272eabce1b0a7
tree8ca9f079520f4ee2b5919fce1c408d79e0ad6f31
parent5dca908a9a23247b1428fcfe29e7478575ddf9c4
sd-journal: fix corrupted journal handling of generic_array_bisect()

Let's consider the following case:
- the direction is down,
- no cached entry,
- the array has 5 entry objects,
- the function test_object() reutns TEST_LEFT for the 1st object,
- the 2nd, 3rd, and 4th objects are broken, so generic_array_bisect_step()
  returns TEST_RIGHT for the object.

Then, previously, generic_array_bisect_step() updated the values like the following:
  0th: (m = 5, left = 0, right = 4, i = 4) -> (m = 4, left = 0, right = 3, RIGHT)
  1st: (m = 4, left = 0, right = 3, i = 1) -> (m = 4, left = 2, right = 3, LEFT)
  2nd: (m = 4, left = 2, right = 3, i = 2) -> (m = 2, left = 2, right = 1, RIGHT) <- ouch!!
So, assert(left < right) in generic_array_bisect() was triggered.
See issue #30210.

In such situation, there is no matching entry in the array. By returning
TEST_GOTO_PREVIOUS, generic_array_bisect() handles the result so.

Fixes a bug introduced by ab8f553d1e09088fb1f633e014299e7bf6c30c9e.

Fixes #30210.
src/libsystemd/sd-journal/journal-file.c
test/units/testsuite-04.journal.sh