From 73ea6854529e2ccfb8cf21218012388c4ef1888f Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 25 Aug 2012 12:04:06 -0700 Subject: [PATCH] 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. This introduces a new connection error code: XCB_CONN_CLOSED_INVALID_SCREEN Signed-off-by: Jeremy Huddleston Sequoia Signed-off-by: Alan Coopersmith --- src/xcb.h | 4 ++++ src/xcb_util.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/xcb.h b/src/xcb.h index 44f650a..0e1333a 100644 --- a/src/xcb.h +++ b/src/xcb.h @@ -84,6 +84,9 @@ extern "C" { /** Connection closed, error during parsing display string. */ #define XCB_CONN_CLOSED_PARSE_ERR 5 +/** Connection closed because the server does not have a screen matching the display. */ +#define XCB_CONN_CLOSED_INVALID_SCREEN 6 + #define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1)) /* Opaque structures */ @@ -423,6 +426,7 @@ int xcb_get_file_descriptor(xcb_connection_t *c); * @return XCB_CONN_CLOSED_MEM_INSUFFICIENT, when memory not available. * @return XCB_CONN_CLOSED_REQ_LEN_EXCEED, exceeding request length that server accepts. * @return XCB_CONN_CLOSED_PARSE_ERR, error during parsing display string. + * @return XCB_CONN_CLOSED_INVALID_SCREEN, because the server does not have a screen matching the display. */ int xcb_connection_has_error(xcb_connection_t *c); diff --git a/src/xcb_util.c b/src/xcb_util.c index 45f66cb..1a9006a 100644 --- a/src/xcb_util.c +++ b/src/xcb_util.c @@ -464,6 +464,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_CLOSED_INVALID_SCREEN); + } + out: free(host); free(protocol); -- 1.7.11.5