From 59592425ae90aea6cb8c2cfef270145b6cf76042 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Mon, 2 Feb 2026 19:47:01 +0100 Subject: [PATCH] dmesg: Check if file is too large 32 bit systems might encounter a file which is larger than 2 GB. The current code would silently truncate the input. Exit with a proper error message instead. Add the equal check to silence compiler warnings on 64 bit systems. Signed-off-by: Tobias Stoeckmann --- sys-utils/dmesg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index 3259f3d64..8af67476c 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -667,6 +667,8 @@ static ssize_t mmap_file_buffer(struct dmesg_control *ctl, char **buf) err(EXIT_FAILURE, _("cannot open %s"), ctl->filename); if (fstat(fd, &st)) err(EXIT_FAILURE, _("stat of %s failed"), ctl->filename); + if ((intmax_t)st.st_size >= (intmax_t)SINT_MAX(ssize_t)) + err(EXIT_FAILURE, _("%s is too large"), ctl->filename); *buf = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (*buf == MAP_FAILED) -- 2.47.3