]> git.ipfire.org Git - thirdparty/systemd.git/commit
journal-gatewayd: fix handling of num_skip pointing beyond the last entry
authorJan Čermák <sairon@sairon.cz>
Tue, 24 Jun 2025 16:54:44 +0000 (18:54 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 25 Jun 2025 17:44:59 +0000 (02:44 +0900)
commita7bfb9f76b96888d60b4f287f29dcbf758ba34c0
tree9789ac34c50e8471516ec7cffeaaed1588460d6e
parentf789b17e87b675acf1638a1801d9b16a377742e0
journal-gatewayd: fix handling of num_skip pointing beyond the last entry

When `num_skip` is supplied to the `Range` header, journal-gatewayd
always returns the very last record even though it should have been
skipped. This is because the `sd_journal_next_skip` always returns
non-zero value on the first call, leading to one iteration of the
`request_reader_entries` returning the last record.

To avoid this unexpected behavior, check that the number of lines we
have skipped by is not lower than the requested skip value. If it is,
then it means there are lines which should not be returned now -
decrement the n_skip counter then and return from the function, closing
the stream if follow flag is not set.

Fixes #37954
src/journal-remote/journal-gatewayd.c
test/units/TEST-04-JOURNAL.journal-gatewayd.sh