[Xcb] [PATCH:xwininfo 1/2 v2] Bug 53242 - xwininfo segfaults on invalid screen

Alan Coopersmith alan.coopersmith at oracle.com
Sat Aug 25 14:23:45 PDT 2012


From: David Venz <david.venz at gmail.com>

Check number of screen entries before iterating past the end of the list

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 dsimple.c |    6 ++++++
 1 file changed, 6 insertions(+)

v2: Move new code below declaration of screen_iter to avoid gcc warning of
    mixing code & declarations.

Even though we seem to be heading towards a fix in libxcb, I'm inclined to
still apply this as well, since it doesn't hurt with the new libxcb, and
stops the segfault for people using new xwininfo with older libxcb.  (And
we'll probably get a new xwininfo out before a new libxcb release.)

diff --git a/dsimple.c b/dsimple.c
index e6d320e..51fb231 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -121,6 +121,12 @@ void Setup_Display_And_Screen (
 	/* find our screen */
 	const xcb_setup_t *setup = xcb_get_setup(*dpy);
 	xcb_screen_iterator_t screen_iter = xcb_setup_roots_iterator(setup);
+	int screen_count = xcb_setup_roots_length(setup);
+	if (screen_count <= screen_number)
+	{
+	    Fatal_Error ("unable to access screen %d, max is %d",
+			 screen_number, screen_count-1 );
+	}
 
 	for (i = 0; i < screen_number; i++)
 	    xcb_screen_next(&screen_iter);
-- 
1.7.9.2



More information about the Xcb mailing list