From 695fb59075d6ba8cd773ffe2408423fef02184c9 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 17 Oct 2025 22:48:07 +0900 Subject: [PATCH] coredumpctl: fix condition for checking coredump journal entry If one of PID, UID, GID, or SIGNAL is missing, then parse_uid() and friends in the below will trigger assertion. This fixes that. Also, only PID, UID, GID, SIGNAL, and COMM are mandatory fields, but others are not, hence this drops others from the condition. Moreover, this mekes 'coredumpctl --list' not fail even if there exists a broken coredump entry in journal. (cherry picked from commit 94a23e9c440962634e28b52babcb2b8aadd6ae96) --- src/coredump/coredumpctl.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index d0755d9e1b4..ab535c21870 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -543,7 +543,7 @@ static int resolve_filename(const char *root, char **p) { static int print_list(FILE* file, sd_journal *j, Table *t) { _cleanup_free_ char *mid = NULL, *pid = NULL, *uid = NULL, *gid = NULL, - *sgnl = NULL, *exe = NULL, *comm = NULL, *cmdline = NULL, + *sgnl = NULL, *exe = NULL, *comm = NULL, *filename = NULL, *truncated = NULL, *coredump = NULL; const void *d; size_t l; @@ -568,14 +568,16 @@ static int print_list(FILE* file, sd_journal *j, Table *t) { RETRIEVE(d, l, "COREDUMP_SIGNAL", sgnl); RETRIEVE(d, l, "COREDUMP_EXE", exe); RETRIEVE(d, l, "COREDUMP_COMM", comm); - RETRIEVE(d, l, "COREDUMP_CMDLINE", cmdline); RETRIEVE(d, l, "COREDUMP_FILENAME", filename); RETRIEVE(d, l, "COREDUMP_TRUNCATED", truncated); RETRIEVE(d, l, "COREDUMP", coredump); } - if (!pid && !uid && !gid && !sgnl && !exe && !comm && !cmdline && !filename) - return log_warning_errno(SYNTHETIC_ERRNO(EINVAL), "Empty coredump log entry"); + if (!pid || !uid || !gid || !sgnl || !comm) { + log_warning("Found a coredump entry without mandatory fields (PID=%s, UID=%s, GID=%s, SIGNAL=%s, COMM=%s), ignoring.", + strna(pid), strna(uid), strna(gid), strna(sgnl), strna(comm)); + return 0; + } (void) parse_uid(uid, &uid_as_int); (void) parse_gid(gid, &gid_as_int); @@ -614,7 +616,7 @@ static int print_list(FILE* file, sd_journal *j, Table *t) { TABLE_SIGNAL, normal_coredump ? signal_as_int : 0, TABLE_STRING, present, TABLE_SET_COLOR, color, - TABLE_STRING, exe ?: comm ?: cmdline, + TABLE_STRING, exe ?: comm, TABLE_SIZE, size); if (r < 0) return table_log_add_error(r); -- 2.47.3