[Xcb] [PATCH:xcb-util] Make sure wm_class name strings are null-terminated

Alan Coopersmith alan.coopersmith at oracle.com
Mon Jun 14 12:28:33 PDT 2010


Alan Coopersmith wrote:
> I see ICCCM claims WM_CLASS are always null-terminated, when I found
> they weren't always in practice.

After digging into this more, I'm not sure if any patch is needed here.
It depends on whether you want to expose bugs in other people's code, or
protect API callers from them.

ICCCM says WM_CLASS contains two null-terminated strings.   The Xlib
code appears to properly set it in XSetClassHint(), but when it retrieves
it in XGetClassHint(), it calls XGetWindowProperty() which always adds a
trailing null byte to the string it returns, effectively fixing the bad
data for the caller.

The two cases I hit in diff'ing the Xlib & xcb xwininfo output without
the change are:

-     0x3e00001 (has no name): ("iiimx" "")  10x10+0+0  +0+0
+     0x3e00001 (has no name): ("iiim71" "")  10x10+0+0  +0+0

Thanks to the magic of google code search, I found this is simply a bug
in the IIIMF code setting the property directly:

  class_atom = XInternAtom(display, "WM_CLASS", True);
  XChangeProperty(display, httw_id, class_atom, XA_STRING, 8,
                  PropModeReplace, "iiimx", strlen("iiimx"));

(Using strlen leaves off the trailing NULL for the first string, plus there's
 no second string at all.)

                  1 child:
                  0x5400007 "JavaEmbeddedFrame":
("sun-awt-X11-XEmbeddedFramePeer" "org-opensolaris-os-vp-client-swing-App")
24x24+0+0  +1314+2
                     2 children:
-                    0x5400010 "FocusProxy": ("Focus-Proxy-Window" "FocusProxy")
 1x1+-1+-1  +1313+1
+                    0x5400010 "FocusProxy": ("Focus-Proxy-Window"
"FocusProxyFra1")  1x1+-1+-1  +1313+1

And this similarly seems to be a bug in the JDK:

            XAtom xa = XAtom.get(XAtom.XA_WM_CLASS);
            xa.setProperty8(getWindow(), cl[0] + '\0' + cl[1]);

This time they just forgot the second trailing NULL.

(Damn, both would seem to be caused by Sun programmers.)

-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System



More information about the Xcb mailing list