[Mesa-dev] Check for NULL native_window into dri2_wl_create_surface

Submitted by Sinclair Yeh on May 30, 2014, 11:58 p.m.

Details

Message ID 1401494336-15501-1-git-send-email-sinclair.yeh@intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Sinclair Yeh May 30, 2014, 11:58 p.m.
We have customers using NULL as a way to test the robustness of
the API.  Without this check, EGL will segfault trying to
dereference dri2_surf->wl_win->private because wl_win is
NULL.

This fix adds a check and sets EGL_BAD_NATIVE_WINDOW
---
 src/egl/drivers/dri2/platform_wayland.c | 7 +++++++
 1 file changed, 7 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 537d26e..66f51e9 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -130,6 +130,13 @@  dri2_wl_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
 
    (void) drv;
 
+   if (NULL == window)
+   {
+      _eglError(EGL_BAD_NATIVE_WINDOW, "dri2_create_surface");
+      return NULL;
+   }
+
+
    dri2_surf = malloc(sizeof *dri2_surf);
    if (!dri2_surf) {
       _eglError(EGL_BAD_ALLOC, "dri2_create_surface");

Comments

On 05/30/2014 04:58 PM, Sinclair Yeh wrote:
> We have customers using NULL as a way to test the robustness of
> the API.  Without this check, EGL will segfault trying to
> dereference dri2_surf->wl_win->private because wl_win is
> NULL.

It sounds like we need a piglit test for this... :)

Should this check actually go at a higher level?  It seems that other
window system back-ends could have the same problem.

> This fix adds a check and sets EGL_BAD_NATIVE_WINDOW

It looks like this same code exists in the 10.2 branch and the 10.1
branch.  This patch should be tagged with:

Cc: "10.1 10.2" <mesa-stable@lists.freedesktop.org>

> ---
>  src/egl/drivers/dri2/platform_wayland.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
> index 537d26e..66f51e9 100644
> --- a/src/egl/drivers/dri2/platform_wayland.c
> +++ b/src/egl/drivers/dri2/platform_wayland.c
> @@ -130,6 +130,13 @@ dri2_wl_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
>  
>     (void) drv;
>  
> +   if (NULL == window)
> +   {

    if (window == NULL) {

> +      _eglError(EGL_BAD_NATIVE_WINDOW, "dri2_create_surface");
> +      return NULL;
> +   }
> +
> +
>     dri2_surf = malloc(sizeof *dri2_surf);
>     if (!dri2_surf) {
>        _eglError(EGL_BAD_ALLOC, "dri2_create_surface");
>