fix crash when validating an invalid EGL objects
the code that validated EGL objects dereferenced the object
to access its EGLDisplay -- needed for validation (!).
This was wrong for two reasons, first we dereferenced the object
before validating it (potentially leading to a crash), secondly
we didn't validate that the object existed in the right EGLDisplay.
We now use the EGLDisplay passed by the user API.
Change-Id: I66f9e851d4f8507892a6b1fee3065f124c4e7138
diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp
index 1e43195..6ad06af 100644
--- a/opengl/libs/EGL/egl.cpp
+++ b/opengl/libs/EGL/egl.cpp
@@ -212,16 +212,20 @@
EGLImageKHR egl_get_image_for_current_context(EGLImageKHR image)
{
- ImageRef _i(image);
- if (!_i.get())
- return EGL_NO_IMAGE_KHR;
-
EGLContext context = egl_tls_t::getContext();
if (context == EGL_NO_CONTEXT || image == EGL_NO_IMAGE_KHR)
return EGL_NO_IMAGE_KHR;
egl_context_t const * const c = get_context(context);
- if (c == NULL) // this should never happen
+ if (c == NULL) // this should never happen, by construction
+ return EGL_NO_IMAGE_KHR;
+
+ egl_display_t* display = egl_display_t::get(c->dpy);
+ if (display == NULL) // this should never happen, by construction
+ return EGL_NO_IMAGE_KHR;
+
+ ImageRef _i(display, image);
+ if (!_i.get())
return EGL_NO_IMAGE_KHR;
// here we don't validate the context because if it's been marked for