From fd83572c67d6025bb893e5c6bc679e5e77e83327 Mon Sep 17 00:00:00 2001
From: David Venz <david.venz@gmail.com>
Date: Sat, 25 Aug 2012 12:06:22 -0700
Subject: [PATCH:xwininfo] Bug 53242 - xwininfo segfaults on invalid screen

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

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

diff --git a/dsimple.c b/dsimple.c
index e6d320e..17273b8 100644
--- a/dsimple.c
+++ b/dsimple.c
@@ -120,6 +120,12 @@ void Setup_Display_And_Screen (
     if (screen) {
 	/* find our screen */
 	const xcb_setup_t *setup = xcb_get_setup(*dpy);
+	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 );
+	}
 	xcb_screen_iterator_t screen_iter = xcb_setup_roots_iterator(setup);
 
 	for (i = 0; i < screen_number; i++)
-- 
1.7.9.2
