From c94017f9e569bf643e0b72bca28748148b29ac17 Mon Sep 17 00:00:00 2001 From: Mikhail Dmitrichenko Date: Mon, 13 Apr 2026 12:18:03 +0300 Subject: [PATCH] vfb: use snprintf when writing XWD window name The window name buffer after XWDFileHeader is fixed at XWD_WINDOW_NAME_LEN (60 bytes). sprintf could overflow when hostname is close to maximum length and combined with the prefix "Xvfb " + display + screen number. Switch to snprintf to guarantee we never write beyond the allocated buffer. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Mikhail Dmitrichenko Part-of: --- hw/vfb/InitOutput.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c index 916605ff4f..83452abd5a 100644 --- a/hw/vfb/InitOutput.c +++ b/hw/vfb/InitOutput.c @@ -740,8 +740,8 @@ vfbWriteXWDFileHeader(ScreenPtr pScreen) struct xhostname hn; xhostname(&hn); hn.name[XWD_WINDOW_NAME_LEN - 1] = 0; - sprintf((char *) (pXWDHeader + 1), "Xvfb %s:%s.%d", hn.name, display, - pScreen->myNum); + snprintf((char *)(pXWDHeader + 1), XWD_WINDOW_NAME_LEN, + "Xvfb %.40s:%.10s.%d", hn.name, display, pScreen->myNum); /* write colormap pixel slot values */