Skip to content

Commit 8ff7a5c

Browse files
committed
journalctl: don't assert on MESSAGE field without "MESSAGE=" prefix
sd_journal_get_data() can return a MESSAGE data object whose payload does not start with "MESSAGE=", e.g. when the journal file is corrupted. Instead of aborting the whole process, log and skip over such an entry like we do for other bad/missing fields. [ 87.287390] post.sh[1619]: + journalctl -q -o short-monotonic --grep 'didn'\''t pass validation' [ 87.287844] post.sh[1620]: + grep -v test-varlink-idl [ 87.325676] post.sh[1619]: Assertion 'message = startswith(message, "MESSAGE=")' failed at src/journal/journalctl-show.c:261, function show(). Aborting. #0 0x00007fb47b49a29c n/a (libc.so.6 + 0x9a29c) #1 0x00007fb47b43e7d0 raise (libc.so.6 + 0x3e7d0) systemd#2 0x00007fb47b425681 abort (libc.so.6 + 0x25681) systemd#3 0x00007fb47b8a1ace log_assert_failed (libsystemd-shared-261~rc2.so + 0xa1ace) systemd#4 0x000055f8e1ef9ddb show (journalctl + 0xcddb) systemd#5 0x000055f8e1efa6ee action_show (journalctl + 0xd6ee) systemd#6 0x000055f8e1ef3c20 run (journalctl + 0x6c20) systemd#7 0x00007fb47b427741 n/a (libc.so.6 + 0x27741) systemd#8 0x00007fb47b427879 __libc_start_main (libc.so.6 + 0x27879) systemd#9 0x000055f8e1ef4915 _start (journalctl + 0x7915) Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7bd3a80 commit 8ff7a5c

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/journal/journalctl-show.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,18 @@ static int show(Context *c) {
258258
return log_error_errno(r, "Failed to get MESSAGE field: %m");
259259
}
260260

261-
assert_se(message = startswith(message, "MESSAGE="));
261+
message = startswith(message, "MESSAGE=");
262+
if (!message) {
263+
/* The data object doesn't carry the expected field prefix, e.g. because
264+
* the journal file is corrupted. Skip over it instead of aborting. */
265+
log_notice("MESSAGE field does not start with \"MESSAGE=\", skipping.");
266+
267+
if (!arg_reverse)
268+
c->until_safe = false;
269+
270+
c->need_seek = true;
271+
continue;
272+
}
262273

263274
r = pattern_matches_and_log(arg_compiled_pattern, message,
264275
len - strlen("MESSAGE="), highlight);

0 commit comments

Comments
 (0)