summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-journal/sd-journal.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2021-11-17 16:54:35 +0100
committerDaan De Meyer <daan.j.demeyer@gmail.com>2021-11-18 22:43:15 +0100
commit5a94a2bf2b9c9ae362dd4a7c2e6b263c55545036 (patch)
tree42dbf7d38fe068992e864d93acceb692d3a41904 /src/libsystemd/sd-journal/sd-journal.c
parentgetty-generator: add kernel cmdline and env vars to disable it (diff)
downloadsystemd-5a94a2bf2b9c9ae362dd4a7c2e6b263c55545036.tar.xz
systemd-5a94a2bf2b9c9ae362dd4a7c2e6b263c55545036.zip
journal: Skip over corrupt entry items in enumerate_data()
Similar to sd_journal_next(), if trying to access an entry item offset's data results in EBADMSG, skip to the next entry item so we handle corruption better. Fixes #21407
Diffstat (limited to '')
-rw-r--r--src/libsystemd/sd-journal/sd-journal.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c
index fa9f420e06..8089f2bcc9 100644
--- a/src/libsystemd/sd-journal/sd-journal.c
+++ b/src/libsystemd/sd-journal/sd-journal.c
@@ -2422,10 +2422,8 @@ static int return_data(
_public_ int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t *size) {
JournalFile *f;
- uint64_t p, n;
- le64_t le_hash;
- int r;
Object *o;
+ int r;
assert_return(j, -EINVAL);
assert_return(!journal_pid_changed(j), -ECHILD);
@@ -2443,26 +2441,39 @@ _public_ int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t
if (r < 0)
return r;
- n = journal_file_entry_n_items(o);
- if (j->current_field >= n)
- return 0;
+ for (uint64_t n = journal_file_entry_n_items(o); j->current_field < n; j->current_field++) {
+ uint64_t p;
+ le64_t le_hash;
- p = le64toh(o->entry.items[j->current_field].object_offset);
- le_hash = o->entry.items[j->current_field].hash;
- r = journal_file_move_to_object(f, OBJECT_DATA, p, &o);
- if (r < 0)
- return r;
+ p = le64toh(o->entry.items[j->current_field].object_offset);
+ le_hash = o->entry.items[j->current_field].hash;
+ r = journal_file_move_to_object(f, OBJECT_DATA, p, &o);
+ if (r == -EBADMSG) {
+ log_debug("Entry item %"PRIu64" data object is bad, skipping over it.", j->current_field);
+ continue;
+ }
+ if (r < 0)
+ return r;
- if (le_hash != o->data.hash)
- return -EBADMSG;
+ if (le_hash != o->data.hash) {
+ log_debug("Entry item %"PRIu64" hash is bad, skipping over it.", j->current_field);
+ continue;
+ }
- r = return_data(j, f, o, data, size);
- if (r < 0)
- return r;
+ r = return_data(j, f, o, data, size);
+ if (r == -EBADMSG) {
+ log_debug("Entry item %"PRIu64" data payload is bad, skipping over it.", j->current_field);
+ continue;
+ }
+ if (r < 0)
+ return r;
- j->current_field++;
+ j->current_field++;
- return 1;
+ return 1;
+ }
+
+ return 0;
}
_public_ int sd_journal_enumerate_available_data(sd_journal *j, const void **data, size_t *size) {