Skip to content

Commit eeb29e1

Browse files
kbrennemanamshafer
authored andcommitted
Check for a duplicate wl_surface in wlEglCreatePlatformWindowSurfaceHook
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.
1 parent c24fe06 commit eeb29e1

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/wayland-eglsurface.c

+22-3
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,10 @@ EGLSurface wlEglCreatePlatformWindowSurfaceHook(EGLDisplay dpy,
26522652
WlEglDisplay *display = wlEglAcquireDisplay(dpy);
26532653
WlEglPlatformData *data = NULL;
26542654
WlEglSurface *surface = NULL;
2655+
WlEglSurface *existingSurf = NULL;
26552656
struct wl_egl_window *window = (struct wl_egl_window *)nativeWin;
2657+
struct wl_surface *wsurf = NULL;
2658+
long int wver = 0;
26562659
EGLBoolean res = EGL_FALSE;
26572660
EGLint err = EGL_SUCCESS;
26582661
EGLint surfType;
@@ -2683,6 +2686,23 @@ EGLSurface wlEglCreatePlatformWindowSurfaceHook(EGLDisplay dpy,
26832686
goto fail;
26842687
}
26852688

2689+
getWlEglWindowVersionAndSurface(window, &wver, &wsurf);
2690+
if (wsurf == NULL) {
2691+
err = EGL_BAD_ALLOC;
2692+
goto fail;
2693+
}
2694+
2695+
// Make sure that we don't have any existing EGLSurfaces for this
2696+
// wl_surface. The driver_private check above isn't sufficient for this: If
2697+
// the app calls wl_egl_window_create more than once on the same
2698+
// wl_surface, then it would get multiple wl_egl_window structs.
2699+
wl_list_for_each(existingSurf, &display->wlEglSurfaceList, link) {
2700+
if (existingSurf->wlSurface == wsurf) {
2701+
err = EGL_BAD_ALLOC;
2702+
goto fail;
2703+
}
2704+
}
2705+
26862706
res = data->egl.getConfigAttrib(dpy, config, EGL_SURFACE_TYPE, &surfType);
26872707

26882708
if (!res || !(surfType & EGL_STREAM_BIT_KHR)) {
@@ -2757,9 +2777,8 @@ EGLSurface wlEglCreatePlatformWindowSurfaceHook(EGLDisplay dpy,
27572777
// Create per surface wayland queue
27582778
surface->wlEventQueue = wl_display_create_queue(display->nativeDpy);
27592779

2760-
getWlEglWindowVersionAndSurface(window,
2761-
&surface->wlEglWinVer,
2762-
&surface->wlSurface);
2780+
surface->wlEglWinVer = wver;
2781+
surface->wlSurface = wsurf;
27632782

27642783
err = assignWlEglSurfaceAttribs(surface, attribs);
27652784
if (err != EGL_SUCCESS) {

0 commit comments

Comments
 (0)