From 1efaa85889051978f806c4ea7c6d4997329624e5 Mon Sep 17 00:00:00 2001 From: Robert Foss Date: Mon, 31 Jul 2023 11:40:23 +0200 Subject: [PATCH] egl: Fix attrib_list[0] == EGL_NONE check _eglGetSurfacelessDisplay(), _eglGetWaylandDisplay() and _eglGetGbmDisplay() handle the attrib_list[0] == EGL_NONE case incorrectly by returning an EGL_BAD_ATTRIBUTE error. Fix this bug, and switch the functions to use switch/case in order to have the same structure as the sibling _eglGetXXXDisplay() functions which support multiple attributes. Fixes: c237539d621 ("egl: Implement EGL_EXT_explicit_device") Signed-off-by: Robert Foss Reviewed-by: Eric Engestrom Part-of: --- src/egl/main/egldisplay.c | 75 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 2bfe271..1769e19 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -570,14 +570,23 @@ _eglGetGbmDisplay(struct gbm_device *native_display, /* This platform recognizes only EXT_explicit_device */ if (attrib_list) { - if (attrib_list[0] != EGL_DEVICE_EXT) { - _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay"); - return NULL; - } - dev = _eglLookupDevice((void *)attrib_list[1]); - if (!dev) { - _eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay"); - return NULL; + for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) { + EGLAttrib attrib = attrib_list[i]; + EGLAttrib value = attrib_list[i + 1]; + + switch (attrib) { + case EGL_DEVICE_EXT: + dev = _eglLookupDevice((void *)value); + if (!dev) { + _eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay"); + return NULL; + } + break; + + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay"); + return NULL; + } } } @@ -600,14 +609,23 @@ _eglGetWaylandDisplay(struct wl_display *native_display, /* This platform recognizes only EXT_explicit_device */ if (attrib_list) { - if (attrib_list[0] != EGL_DEVICE_EXT) { - _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay"); - return NULL; - } - dev = _eglLookupDevice((void *)attrib_list[1]); - if (!dev) { - _eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay"); - return NULL; + for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) { + EGLAttrib attrib = attrib_list[i]; + EGLAttrib value = attrib_list[i + 1]; + + switch (attrib) { + case EGL_DEVICE_EXT: + dev = _eglLookupDevice((void *)value); + if (!dev) { + _eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay"); + return NULL; + } + break; + + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay"); + return NULL; + } } } @@ -633,14 +651,23 @@ _eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list) /* This platform recognizes only EXT_explicit_device */ if (attrib_list) { - if (attrib_list[0] != EGL_DEVICE_EXT) { - _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay"); - return NULL; - } - if ((native_display && native_display != (void *)attrib_list[1]) || - (native_display != _eglLookupDevice(native_display))) { - _eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay"); - return NULL; + for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) { + EGLAttrib attrib = attrib_list[i]; + EGLAttrib value = attrib_list[i + 1]; + + switch (attrib) { + case EGL_DEVICE_EXT: + if ((native_display && native_display != (void *)value) || + (native_display != _eglLookupDevice(native_display))) { + _eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay"); + return NULL; + } + break; + + default: + _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay"); + return NULL; + } } } -- 2.7.4