From c3b190f9da3a8cd6f98c127220683dd20aed0f9b Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Thu, 5 Apr 2018 12:31:04 -0400 Subject: [PATCH] dmx: Fix some snprintf warnings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit snprintf doesn't terminate the string if it truncates, so things like this are lurking crashers: ../hw/dmx/dmxprop.c: In function ‘dmxPropertyIdentifier.part.0’: ../hw/dmx/dmxprop.c:94:36: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 123 [-Wformat-truncation=] snprintf(buf, sizeof(buf), "%s:%s:%s", DMX_IDENT, hostname, display); ^~ ~~~~~~~~ ../hw/dmx/dmxprop.c:94:5: note: ‘snprintf’ output 7 or more bytes (assuming 262) into a destination of size 128 snprintf(buf, sizeof(buf), "%s:%s:%s", DMX_IDENT, hostname, display); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../hw/dmx/dmxprop.c: In function ‘dmxPropertyWindow’: ../hw/dmx/dmxprop.c:372:36: warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 127 [-Wformat-truncation=] snprintf(buf, sizeof(buf), "%s,%d", id, dmxScreen->index); ^~ ../hw/dmx/dmxprop.c:372:5: note: ‘snprintf’ output between 3 and 140 bytes into a destination of size 128 snprintf(buf, sizeof(buf), "%s,%d", id, dmxScreen->index); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We could be more precise about termination, but meh. Signed-off-by: Adam Jackson Acked-by: Keith Packard --- hw/dmx/dmxprop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/dmx/dmxprop.c b/hw/dmx/dmxprop.c index 4c85268b7..7dfa04af5 100644 --- a/hw/dmx/dmxprop.c +++ b/hw/dmx/dmxprop.c @@ -84,7 +84,7 @@ dmxPropertyIdentifier(void) /* RATS: These buffers are only used in * length-limited calls. */ char hostname[256]; - static char buf[128]; + static char buf[512]; static int initialized = 0; if (initialized++) @@ -346,7 +346,7 @@ dmxPropertyWindow(DMXScreenInfo * dmxScreen) Display *dpy = dmxScreen->beDisplay; Window win = dmxScreen->scrnWin; DMXScreenInfo *other; - char buf[128]; /* RATS: only used with snprintf */ + char buf[1024]; /* RATS: only used with snprintf */ if (!dpy) return; /* FIXME: What should be done here if Xdmx is started