Add magic check to confirm WL_EGL_TIZEN private. 35/259535/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Tue, 8 Jun 2021 09:35:18 +0000 (18:35 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Tue, 8 Jun 2021 09:35:18 +0000 (18:35 +0900)
Change-Id: I0f3663c027c4c3e2d14843296b94d81345b3580e
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/wayland-egl-tizen/wayland-egl-tizen-priv.h
src/wayland-egl-tizen/wayland-egl-tizen.c

index caeb5b0eb15df156d31bf2397db7659f507275af..af307daa18c39d63db08ada5446c5ba2c9aa207e 100644 (file)
@@ -9,7 +9,12 @@ extern "C" {
 #include <wayland-client.h>
 #include <wayland-egl.h>
 
+#ifndef WL_EGL_TIZEN_MAGIC
+#define WL_EGL_TIZEN_MAGIC 0xDEF00123
+#endif
+
 struct tizen_private {
+       unsigned int magic;
        int rotation;
        int frontbuffer_mode;
        int transform;
@@ -27,11 +32,13 @@ struct tizen_private {
        int (*merge_sync_fds)(void *, int, int);
 };
 
-static struct tizen_private* tizen_private_create()
+static struct tizen_private*
+tizen_private_create()
 {
        struct tizen_private *private = NULL;
        private = (struct tizen_private *)calloc(1, sizeof(struct tizen_private));
        if (private) {
+               private->magic = WL_EGL_TIZEN_MAGIC;
                private->rotation = 0;
                private->frontbuffer_mode = 0;
                private->transform = 0;
index 2fb876c68b912b30bcea762348cbe46917e48256..ff166039d27e3589e36ce55393752d2382f634f1 100644 (file)
 #define WL_EGL_ERR(f, x...)            LOGE(FONT_RED f FONT_DEFAULT, ##x)
 #define WL_EGL_WARN(f, x...)   LOGW(FONT_YELLOW f FONT_DEFAULT, ##x)
 
+static int
+_wl_egl_tizen_magic_check(struct tizen_private *private)
+{
+       if (private->magic != WL_EGL_TIZEN_MAGIC)
+               return 0;
+
+       return 1;
+}
+
 void
 wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window,
                                                                 int rotation)
@@ -41,6 +50,11 @@ wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window,
                egl_window->driver_private = (void *)private;
        } else {
                private = (struct tizen_private *)egl_window->driver_private;
+               if (!_wl_egl_tizen_magic_check(private)) {
+                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                               egl_window);
+                       return;
+               }
        }
 
        if (private->rotation == rotation) {
@@ -76,6 +90,11 @@ wl_egl_window_tizen_get_capabilities(struct wl_egl_window *egl_window)
                egl_window->driver_private = (void *)private;
        } else {
                private = (struct tizen_private *)egl_window->driver_private;
+               if (!_wl_egl_tizen_magic_check(private)) {
+                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                               egl_window);
+                       return -1;
+               }
        }
 
        if (private->get_rotation_capability)
@@ -106,6 +125,11 @@ wl_egl_window_tizen_set_buffer_transform(struct wl_egl_window *egl_window,
                egl_window->driver_private = (void *)private;
        } else {
                private = (struct tizen_private *)egl_window->driver_private;
+               if (!_wl_egl_tizen_magic_check(private)) {
+                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                               egl_window);
+                       return;
+               }
        }
 
        if (private->transform == wl_output_transform) {
@@ -137,6 +161,11 @@ wl_egl_window_tizen_set_frontbuffer_mode(struct wl_egl_window *egl_window,
                egl_window->driver_private = (void *)private;
        } else {
                private = (struct tizen_private *)egl_window->driver_private;
+               if (!_wl_egl_tizen_magic_check(private)) {
+                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                               egl_window);
+                       return;
+               }
        }
 
        private->frontbuffer_mode = set;
@@ -166,6 +195,11 @@ wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window,
                egl_window->driver_private = (void *)private;
        } else {
                private = (struct tizen_private *)egl_window->driver_private;
+               if (!_wl_egl_tizen_magic_check(private)) {
+                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                               egl_window);
+                       return;
+               }
        }
 
        if (private->window_transform == window_transform) {
@@ -196,6 +230,11 @@ wl_egl_window_tizen_get_window_serial(struct wl_egl_window *egl_window)
                egl_window->driver_private = (void *)private;
        } else {
                private = (struct tizen_private *)egl_window->driver_private;
+               if (!_wl_egl_tizen_magic_check(private)) {
+                       WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                               egl_window);
+                       return 0;
+               }
        }
 
        return private->serial;
@@ -217,6 +256,12 @@ wl_egl_window_tizen_set_window_serial(struct wl_egl_window *egl_window,
                return;
        }
 
+       if (!_wl_egl_tizen_magic_check(private)) {
+               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                       egl_window);
+               return;
+       }
+
        if (private->set_window_serial_callback)
                private->set_window_serial_callback(egl_window, egl_window->driver_private,
                                                                                        serial);
@@ -238,6 +283,12 @@ wl_egl_window_tizen_create_commit_sync_fd(struct wl_egl_window *egl_window)
                return -1;
        }
 
+       if (!_wl_egl_tizen_magic_check(private)) {
+               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                       egl_window);
+               return -1;
+       }
+
        if (private->create_commit_sync_fd)
                return private->create_commit_sync_fd(egl_window, egl_window->driver_private);
 
@@ -260,6 +311,12 @@ wl_egl_window_tizen_create_presentation_sync_fd(struct wl_egl_window *egl_window
                return -1;
        }
 
+       if (!_wl_egl_tizen_magic_check(private)) {
+               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                       egl_window);
+               return -1;
+       }
+
        if (private->create_presentation_sync_fd)
                return private->create_presentation_sync_fd(egl_window, egl_window->driver_private);
 
@@ -283,6 +340,12 @@ wl_egl_window_tizen_merge_sync_fds(struct wl_egl_window *egl_window,
                return -1;
        }
 
+       if (!_wl_egl_tizen_magic_check(private)) {
+               WL_EGL_WARN("driver_private of wl_egl_window(%p) is not tizen_private",
+                                       egl_window);
+               return -1;
+       }
+
        if (private->merge_sync_fds)
                return private->merge_sync_fds(egl_window->driver_private, sync_fd1, sync_fd2);