From: Tobias Stoeckmann Date: Mon, 2 Feb 2026 18:47:01 +0000 (+0100) Subject: dmesg: Check if file is too large X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59592425ae90aea6cb8c2cfef270145b6cf76042;p=thirdparty%2Futil-linux.git 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 --- 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)