Skip to content

Commit 2a64814

Browse files
committed
in_systemd: add explicit restarts for the journal data cursor
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 6345fd1 commit 2a64814

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

plugins/in_systemd/systemd.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ static int in_systemd_collect(struct flb_input_instance *ins,
308308
}
309309

310310
while ((ret_j = sd_journal_next(ctx->j)) > 0) {
311+
/*
312+
* Reset the journal data cursor as soon as we advance to the next
313+
* entry. Newer libsystemd releases keep Zstandard decompression
314+
* state across data lookups, so carrying over the state from a
315+
* previous entry can trigger use-after-free bugs while we fetch the
316+
* first fields (for example when retrieving _SYSTEMD_UNIT for
317+
* dynamic tags).
318+
*/
319+
sd_journal_restart_data(ctx->j);
311320
/* If the tag is composed dynamically, gather the Systemd Unit name */
312321
if (ctx->dynamic_tag) {
313322
ret = sd_journal_get_data(ctx->j, "_SYSTEMD_UNIT", &data, &length);
@@ -384,6 +393,15 @@ static int in_systemd_collect(struct flb_input_instance *ins,
384393
/* Pack every field in the entry */
385394
entries = 0;
386395
skip_entries = 0;
396+
397+
/*
398+
* Restart the journal data cursor before enumerating the fields for
399+
* this entry. sd_journal_get_data() above may advance the cursor, so
400+
* reset it again to ensure enumeration starts from the first field and
401+
* that libsystemd does not reuse a stale decompression context.
402+
*/
403+
sd_journal_restart_data(ctx->j);
404+
387405
while (sd_journal_enumerate_data(ctx->j, &data, &length) > 0 &&
388406
entries < ctx->max_fields) {
389407
key = (const char *) data;

0 commit comments

Comments
 (0)