[Xcb] [PATCH:libxcb v5] Return connection failure if display string specifies non-existent string

Jeremy Huddleston Sequoia jeremyhu at freedesktop.org
Sat Aug 25 15:02:54 PDT 2012


All 3:

Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

On Aug 25, 2012, at 14:16, Alan Coopersmith <alan.coopersmith at oracle.com> wrote:

> 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 <jeremyhu at apple.com>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
> src/xcb.h      |    4 ++++
> src/xcb_conn.c |    5 +++++
> src/xcb_util.c |   10 ++++++++++
> 3 files changed, 19 insertions(+)
> 
> v2: Jeremy introduced new connection error code XCB_CONN_CLOSED_INVALID_SCREEN
>    https://bugs.freedesktop.org/attachment.cgi?id=66113&action=edit
> 
> v3: Jeremy fixed my bug in failing to dereference pscreen before comparing
>    https://bugs.freedesktop.org/attachment.cgi?id=66114&action=edit
> 
> v4: Made error path more like the rest of the function, to avoid memory leaks
>    https://bugs.freedesktop.org/attachment.cgi?id=66115&action=edit
> 
> v5: Add a new static const object for XCB_CONN_CLOSED_INVALID_SCREEN for
>    _xcb_conn_ret_error to return so callers can see the new error code.
>    Don't check screen number if a previous step had an error, since that
>    means c just points to an int now, not a full xcb_connection_t.
> 
> 
> diff --git a/src/xcb.h b/src/xcb.h
> index 179af84..f7dc6af 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_conn.c b/src/xcb_conn.c
> index 7202cc5..7979491 100644
> --- a/src/xcb_conn.c
> +++ b/src/xcb_conn.c
> @@ -66,6 +66,7 @@ typedef struct {
> static const int xcb_con_error = XCB_CONN_ERROR;
> static const int xcb_con_closed_mem_er = XCB_CONN_CLOSED_MEM_INSUFFICIENT;
> static const int xcb_con_closed_parse_er = XCB_CONN_CLOSED_PARSE_ERR;
> +static const int xcb_con_closed_screen_er = XCB_CONN_CLOSED_INVALID_SCREEN;
> 
> static int set_fd_flags(const int fd)
> {
> @@ -349,6 +350,10 @@ xcb_connection_t *_xcb_conn_ret_error(int err)
>         {
>             return (xcb_connection_t *) &xcb_con_closed_parse_er;
>         }
> +        case XCB_CONN_CLOSED_INVALID_SCREEN:
> +        {
> +            return (xcb_connection_t *) &xcb_con_closed_screen_er;
> +        }
>         case XCB_CONN_ERROR:
>         default:
>         {
> diff --git a/src/xcb_util.c b/src/xcb_util.c
> index e480d75..463d085 100644
> --- a/src/xcb_util.c
> +++ b/src/xcb_util.c
> @@ -467,6 +467,16 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
>     else
>         c = xcb_connect_to_fd(fd, 0);
> 
> +    if(c->has_error)
> +        goto out;
> +
> +    /* Make sure requested screen number is in bounds for this server */
> +    if((screenp != NULL) && (*screenp >= (int) c->setup->roots_len)) {
> +        xcb_disconnect(c);
> +        c = _xcb_conn_ret_error(XCB_CONN_CLOSED_INVALID_SCREEN);
> +        goto out;
> +    }
> +
> out:
>     free(host);
>     free(protocol);
> -- 
> 1.7.9.2
> 
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb
> 



More information about the Xcb mailing list