From 04d64d93321b17c7f75f7ab4d4d9afc8950b1165 Mon Sep 17 00:00:00 2001
From: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Sat, 25 Aug 2012 12:04:06 -0700
Subject: [PATCH:libxcb] Return connection failure if display string specifies
 non-existent string

Matches the behaviour of Xlib - if you set DISPLAY to :0.1 but only have
one screen, closes connection and returns error.

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

diff --git a/src/xcb_util.c b/src/xcb_util.c
index e480d75..31dda7b 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -467,6 +467,12 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
     else
         c = xcb_connect_to_fd(fd, 0);
 
+    /* Make sure requested screen number is in bounds for this server */
+    if((screenp != NULL) && (screenp > c->setup->roots_len)) {
+        xcb_disconnect(c);
+        return _xcb_conn_ret_error(XCB_CONN_ERROR);
+    }
+
 out:
     free(host);
     free(protocol);
-- 
1.7.9.2
