From: Tobias Stoeckmann Date: Mon, 2 Feb 2026 18:28:32 +0000 (+0100) Subject: dmesg: Only check for newline if input exists X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f6b555f6c1aa7eb529b162385e92e0bb9bebcb7;p=thirdparty%2Futil-linux.git dmesg: Only check for newline if input exists If a memory mapped file does not end with a newline, do not check for its existence. Accessing *end would lead to an out of boundary read. Signed-off-by: Tobias Stoeckmann --- diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 12e40a350..3259f3d64 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -946,15 +946,15 @@ static int get_next_syslog_record(struct dmesg_control *ctl, rec->mesg_size = end - begin; } - /* Don't count \n from the last message to the message size */ - if (*end != '\n' && *(end - 1) == '\n') - rec->mesg_size--; - rec->next_size -= end - rec->next; rec->next = rec->next_size > 0 ? end + 1 : NULL; if (rec->next_size > 0) rec->next_size--; + /* Don't count \n from the last message to the message size */ + if ((!rec->next || *end != '\n') && *(end - 1) == '\n') + rec->mesg_size--; + return 0; }