Skip to content

Commit

Permalink
EGL: Check for EGL_NO_DISPLAY before calling eglQueryContext
Browse files Browse the repository at this point in the history
According to the reference documentation that could lead
to undefined behavior.

Reference:

  https://registry.khronos.org/EGL/sdk/docs/man/html/eglGetCurrentDisplay.xhtml
  • Loading branch information
lb90 committed Nov 11, 2024
1 parent 703caed commit fcb9913
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/dispatch_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,16 @@ epoxy_get_core_proc_address(const char *name, int core_version)
static EGLenum
epoxy_egl_get_current_gl_context_api(void)
{
EGLDisplay *egl_display = eglGetCurrentDisplay();
EGLContext *egl_context = eglGetCurrentContext();
EGLint curapi;

if (!api.egl_handle)
return EGL_NONE;

if (eglQueryContext(eglGetCurrentDisplay(), eglGetCurrentContext(),
if (egl_display == EGL_NO_DISPLAY ||
eglQueryContext(egl_display,
egl_context,
EGL_CONTEXT_CLIENT_TYPE, &curapi) == EGL_FALSE) {
(void)eglGetError();
return EGL_NONE;
Expand Down Expand Up @@ -835,8 +839,13 @@ epoxy_get_bootstrap_proc_address(const char *name)
case EGL_OPENGL_API:
return epoxy_gl_dlsym(name);
case EGL_OPENGL_ES_API:
if (eglQueryContext(eglGetCurrentDisplay(),
eglGetCurrentContext(),
{
EGLDisplay *egl_display = eglGetCurrentDisplay();
EGLContext *egl_context = eglGetCurrentContext();

if (egl_display != EGL_NO_DISPLAY &&
eglQueryContext(egl_display,
egl_context,
EGL_CONTEXT_CLIENT_VERSION,
&version)) {
if (version >= 2)
Expand All @@ -845,6 +854,7 @@ epoxy_get_bootstrap_proc_address(const char *name)
return epoxy_gles1_dlsym(name);
}
}
}
}
#endif /* PLATFORM_HAS_EGL */

Expand Down

0 comments on commit fcb9913

Please sign in to comment.