From e4d189f26f551e2628b2d0552e50e16ed49d25ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Wed, 5 Feb 2025 14:43:34 +0100 Subject: [PATCH] egl/glx/sw: Check xcb_query_extension_reply return value for MIT-SHM For consistency with other xcb_query_extension_reply callers. v2: * Now with less use-after-free. (Eric Engestrom) Reviewed-by: Eric Engestrom Part-of: --- src/egl/drivers/dri2/platform_x11.c | 2 +- src/glx/drisw_glx.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 4895e6d24fd..f573f99ac8b 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -1765,7 +1765,7 @@ check_xshm(struct dri2_egl_display *dri2_dpy) shm_cookie = xcb_query_extension(dri2_dpy->conn, 7, "MIT-SHM"); shm_reply = xcb_query_extension_reply(dri2_dpy->conn, shm_cookie, NULL); - has_mit_shm = shm_reply->present; + has_mit_shm = shm_reply && shm_reply->present; free(shm_reply); if (!has_mit_shm) return false; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index b5ba0cdd4fc..c567cd6bc19 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -572,16 +572,21 @@ check_xshm(Display *dpy) int ret = True; xcb_query_extension_cookie_t shm_cookie; xcb_query_extension_reply_t *shm_reply; - bool has_mit_shm; shm_cookie = xcb_query_extension(c, 7, "MIT-SHM"); shm_reply = xcb_query_extension_reply(c, shm_cookie, NULL); - xshm_opcode = shm_reply->major_opcode; - has_mit_shm = shm_reply->present; - free(shm_reply); - if (!has_mit_shm) - return False; + if (shm_reply) { + bool has_mit_shm = shm_reply->present; + + if (has_mit_shm) + xshm_opcode = shm_reply->major_opcode; + + free(shm_reply); + + if (!has_mit_shm) + return False; + } cookie = xcb_shm_detach_checked(c, 0); if ((error = xcb_request_check(c, cookie))) {