]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: Check if file is too large
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Feb 2026 18:47:01 +0000 (19:47 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Feb 2026 18:59:33 +0000 (19:59 +0100)
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 <tobias@stoeckmann.org>
sys-utils/dmesg.c

index 3259f3d64775d8b705998f4a700d519f23eeb138..8af67476c9970c3a60742ab70dd38486ef70d990 100644 (file)
@@ -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)