]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: make kmsg read() buffer big enough for kernel
authoranteater <65555601+nt8r@users.noreply.github.com>
Mon, 29 May 2023 20:59:11 +0000 (20:59 +0000)
committerGitHub <noreply@github.com>
Mon, 29 May 2023 20:59:11 +0000 (20:59 +0000)
otherwise, if the kernel log has an item longer than 1024B, our read() gives EINVAL and we stop reading kmsg

sys-utils/dmesg.c

index 45075e50bd1fc0b1b3da4f4234df64c2ad3d75d7..717cc588b2ca3dcc720551f0c824a043ef46fd08 100644 (file)
@@ -179,7 +179,13 @@ struct dmesg_control {
 
        int             kmsg;           /* /dev/kmsg file descriptor */
        ssize_t         kmsg_first_read;/* initial read() return code */
-       char            kmsg_buf[BUFSIZ];/* buffer to read kmsg data */
+       /*
+        * the kernel will give EINVAL if we do read() on /proc/kmsg with
+        * length insufficient for the next message. messages may be up to
+        * PRINTK_MESSAGE_MAX, which is defined as 2048, so we must be
+        * able to buffer at least that much in one call
+        */
+       char            kmsg_buf[2048]; /* buffer to read kmsg data */
 
        usec_t          since;          /* filter records by time */
        usec_t          until;          /* filter records by time */