From 3d21a15f54515097bb64f740838c255909977f5e Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 3 Jun 2025 19:11:21 +0200 Subject: [PATCH] xfree86: fix possible buffer overflow in xf86PrintBanner() There's chance of buffer overflow happending due lack of zero-termination of printed string. Making sure the buffer is always propertly terminated. See: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1821 Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xfree86/common/xf86Init.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index ae556ee7e..5e432597a 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -168,15 +168,14 @@ xf86PrintBanner(void) name.version, name.machine); #ifdef __linux__ do { - char buf[80]; int fd = open("/proc/cmdline", O_RDONLY); if (fd != -1) { + char buf[82] = { 0 }; xf86ErrorFVerb(0, "Kernel command line: "); - memset(buf, 0, 80); - while (read(fd, buf, 80) > 0) { + while (read(fd, buf, sizeof(buf)-2) > 0) { xf86ErrorFVerb(0, "%.80s", buf); - memset(buf, 0, 80); + memset(buf, 0, sizeof(buf)); } close(fd); }