[PATCH xserver 2/8] dmx: Fix some snprintf warnings.

Adam Jackson ajax at redhat.com
Thu Apr 5 17:13:55 UTC 2018


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 <ajax at redhat.com>
---
 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 4c85268b79..7dfa04af5a 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
-- 
2.16.2



More information about the xorg-devel mailing list