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

2018-04-06 Thread Emil Velikov
On 6 April 2018 at 09:44, Peter Hutterer  wrote:
> 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?
>
Indeed - quick search points to the following
https://stackoverflow.com/a/13067917

Dummy test with gcc 7.2.1 -Wall -Wextra -pedantic -std=c89/99/11 (yes,
c89 is missing the API) shows proper NULL terminated strings.

-Emil
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

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

2018-04-06 Thread Peter Hutterer
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 
> ---
>  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@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel
> 
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

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

2018-04-05 Thread Adam Jackson
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 
---
 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@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel