Module: Mesa
Branch: main
Commit: 45ea17d2449576ffc1bf3c602d679c77dd63f39f
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=45ea17d2449576ffc1bf3c602d679c77dd63f39f

Author: Illia Polishchuk <[email protected]>
Date:   Tue Apr 25 11:42:20 2023 +0300

glx: add fail check for current context in another thread

The GLX spec for glXMakeCurrent (3.3):
"If ctx is current to some other thread, then glXMakeCurrent will generate
a BadAccess error"

The GLX spec for glXCopyContext (3.3):
"If the destination context is current for some thread then a BadAccess
error is generated"

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7961
Reviewed-by: Adam Jackson <[email protected]>
Signed-off-by: Illia Polishchuk <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22546>

---

 src/glx/glxcmds.c    | 8 ++++++++
 src/glx/glxcurrent.c | 9 +++++++++
 2 files changed, 17 insertions(+)

diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c
index 91c4c627bfe..720cff0128c 100644
--- a/src/glx/glxcmds.c
+++ b/src/glx/glxcmds.c
@@ -579,6 +579,14 @@ glXCopyContext(Display * dpy, GLXContext source_user,
 {
    struct glx_context *source = (struct glx_context *) source_user;
    struct glx_context *dest = (struct glx_context *) dest_user;
+
+   /* GLX spec 3.3: If the destination context is current for some thread
+    * then a BadAccess error is generated
+    */
+   if (dest && dest->currentDpy) {
+      __glXSendError(dpy, BadAccess, 0, X_GLXCopyContext, true);
+      return;
+   }
 #ifdef GLX_USE_APPLEGL
    struct glx_context *gc = __glXGetCurrentContext();
    int errorcode;
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c
index 19b70194ac6..31f0ecca56e 100644
--- a/src/glx/glxcurrent.c
+++ b/src/glx/glxcurrent.c
@@ -138,6 +138,15 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
    __glXSetCurrentContextNull();
 
    if (gc) {
+      /* GLX spec 3.3: If ctx is current to some other thread, then
+       * glXMakeContextCurrent will generate a BadAccess error
+       */
+      if (gc->currentDpy)
+      {
+         __glXUnlock();
+         __glXSendError(dpy, BadAccess, None, opcode, True);
+         return False;
+      }
       /* Attempt to bind the context.  We do this before mucking with
        * gc and __glXSetCurrentContext to properly handle our state in
        * case of an error.

Reply via email to