Skip to content

Commit

Permalink
Check for a duplicate wl_surface in wlEglCreatePlatformWindowSurfaceHook
Browse files Browse the repository at this point in the history
In wlEglCreatePlatformWindowSurfaceHook, check if there's already a
EGLSurface that uses the same wl_surface object, and if so, fail with
EGL_BAD_ALLOC.

We've got a check (using the wl_egl_window::driver_private pointer) to
catch if the app tries to create multiple EGLSurfaces from the same
wl_egl_window. But, an app could still call wl_egl_window_create
multiple times, which would give it multiple wl_egl_window structs for
the same wl_surface.
  • Loading branch information
kbrenneman committed Nov 14, 2024
1 parent 7d1d1aa commit 5e7652c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/wayland-eglsurface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2653,6 +2653,8 @@ EGLSurface wlEglCreatePlatformWindowSurfaceHook(EGLDisplay dpy,
WlEglPlatformData *data = NULL;
WlEglSurface *surface = NULL;
struct wl_egl_window *window = (struct wl_egl_window *)nativeWin;
struct wl_surface *wsurf = NULL;
long int wver = 0;
EGLBoolean res = EGL_FALSE;
EGLint err = EGL_SUCCESS;
EGLint surfType;
Expand Down Expand Up @@ -2683,6 +2685,23 @@ EGLSurface wlEglCreatePlatformWindowSurfaceHook(EGLDisplay dpy,
goto fail;
}

getWlEglWindowVersionAndSurface(window, &wver, &wsurf);
if (wsurf == NULL) {
err = EGL_BAD_ALLOC;
goto fail;
}

// Make sure that we don't have any existing EGLSurfaces for this
// wl_surface. The driver_private check above isn't sufficient for this: If
// the app calls wl_egl_window_create more than once on the same
// wl_surface, then it would get multiple wl_egl_window structs.
wl_list_for_each(surface, &display->wlEglSurfaceList, link) {
if (surface->wlSurface == wsurf) {
err = EGL_BAD_ALLOC;
goto fail;
}
}

res = data->egl.getConfigAttrib(dpy, config, EGL_SURFACE_TYPE, &surfType);

if (!res || !(surfType & EGL_STREAM_BIT_KHR)) {
Expand Down Expand Up @@ -2757,9 +2776,8 @@ EGLSurface wlEglCreatePlatformWindowSurfaceHook(EGLDisplay dpy,
// Create per surface wayland queue
surface->wlEventQueue = wl_display_create_queue(display->nativeDpy);

getWlEglWindowVersionAndSurface(window,
&surface->wlEglWinVer,
&surface->wlSurface);
surface->wlEglWinVer = wver;
surface->wlSurface = wsurf;

err = assignWlEglSurfaceAttribs(surface, attribs);
if (err != EGL_SUCCESS) {
Expand Down

0 comments on commit 5e7652c

Please sign in to comment.