From 47717e62e7f81dfb292a7f2050dc618d25f0c78b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Tue, 8 Jun 2021 18:35:18 +0900 Subject: [PATCH] Add magic check to confirm WL_EGL_TIZEN private. Change-Id: I0f3663c027c4c3e2d14843296b94d81345b3580e Signed-off-by: Joonbum Ko --- src/wayland-egl-tizen/wayland-egl-tizen-priv.h | 9 +++- src/wayland-egl-tizen/wayland-egl-tizen.c | 63 ++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/wayland-egl-tizen/wayland-egl-tizen-priv.h b/src/wayland-egl-tizen/wayland-egl-tizen-priv.h index caeb5b0..af307da 100644 --- a/src/wayland-egl-tizen/wayland-egl-tizen-priv.h +++ b/src/wayland-egl-tizen/wayland-egl-tizen-priv.h @@ -9,7 +9,12 @@ extern "C" { #include #include +#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; diff --git a/src/wayland-egl-tizen/wayland-egl-tizen.c b/src/wayland-egl-tizen/wayland-egl-tizen.c index 2fb876c..ff16603 100644 --- a/src/wayland-egl-tizen/wayland-egl-tizen.c +++ b/src/wayland-egl-tizen/wayland-egl-tizen.c @@ -21,6 +21,15 @@ #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); -- 2.7.4