egl: move Null check to eglGetSyncAttribKHR to prevent Segfault
authorDongwon Kim <dongwon.kim@intel.com>
Tue, 2 Feb 2016 23:06:28 +0000 (15:06 -0800)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 19 Feb 2016 18:23:19 +0000 (18:23 +0000)
Null-check on "*value" is currently done in _eglGetSyncAttrib, which is
after eglGetSyncAttribKHR dereferences it.

Move the check a layer up (in the beginning of eglGetSyncAttribKHR) to
avoid segfaults.

Cc: "11.0 11.1" <mesa-stable@lists.freedesktop.org
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
[Emil Velikov: tweak commit message, add stable tag]
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/egl/main/eglapi.c
src/egl/main/eglsync.c

index 323634e451180fdb3245ced0ce2a8aaa7ae9a59c..32f68233aeb4aa22f34860aa7b2295b4555ff85e 100644 (file)
@@ -1555,8 +1555,14 @@ eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *valu
 static EGLBoolean EGLAPIENTRY
 eglGetSyncAttribKHR(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLint *value)
 {
-   EGLAttrib attrib = *value;
-   EGLBoolean result = eglGetSyncAttrib(dpy, sync, attribute, &attrib);
+   EGLAttrib attrib;
+   EGLBoolean result;
+
+   if (!value)
+      RETURN_EGL_ERROR(NULL, EGL_BAD_PARAMETER, EGL_FALSE);
+
+   attrib = *value;
+   result = eglGetSyncAttrib(dpy, sync, attribute, &attrib);
 
    /* The EGL_KHR_fence_sync spec says this about eglGetSyncAttribKHR:
     *
index 3019e6e9333bf608344f053c54812fd701e6f5fc..999cb480c4b259a60bb33e008f589ddfdd19ea85 100644 (file)
@@ -144,9 +144,6 @@ EGLBoolean
 _eglGetSyncAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
                   EGLint attribute, EGLAttrib *value)
 {
-   if (!value)
-      return _eglError(EGL_BAD_PARAMETER, "eglGetSyncAttribKHR");
-
    switch (attribute) {
    case EGL_SYNC_TYPE_KHR:
       *value = sync->Type;