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

Peter Hutterer peter.hutterer at who-t.net
Fri Apr 6 08:44:28 UTC 2018


On Thu, Apr 05, 2018 at 01:13:55PM -0400, Adam Jackson wrote:
> snprintf doesn't terminate the string if it truncates, so things like
> this are lurking crashers:

it doesn't? which platforms is that on? Apparently windows, from a quick
google but that's about it, right?

Cheers,
   Peter


> 
> ../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
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list