From 0b211c22418acb8c209a71580ce2b262a322bd9b Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 3 Dec 2023 15:21:32 +0000 Subject: Fix [40af63fa24]: Aqua: passing None to XMapWindow() should be fatal --- generic/tkWindow.c | 27 +++++++++++++++------------ macosx/tkMacOSXSubwindows.c | 2 +- macosx/tkMacOSXWm.c | 24 +++++++++++++----------- win/tkWinWindow.c | 16 ++++++++++++---- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/generic/tkWindow.c b/generic/tkWindow.c index 9ab59a3..2058501 100644 --- a/generic/tkWindow.c +++ b/generic/tkWindow.c @@ -1740,16 +1740,18 @@ Tk_MapWindow( TkWmMapWindow(winPtr); return; } - winPtr->flags |= TK_MAPPED; - XMapWindow(winPtr->display, winPtr->window); - event.type = MapNotify; - event.xmap.serial = LastKnownRequestProcessed(winPtr->display); - event.xmap.send_event = False; - event.xmap.display = winPtr->display; - event.xmap.event = winPtr->window; - event.xmap.window = winPtr->window; - event.xmap.override_redirect = winPtr->atts.override_redirect; - Tk_HandleEvent(&event); + if ((winPtr->window != None) + && (XMapWindow(winPtr->display, winPtr->window) == Success)) { + winPtr->flags |= TK_MAPPED; + event.type = MapNotify; + event.xmap.serial = LastKnownRequestProcessed(winPtr->display); + event.xmap.send_event = False; + event.xmap.display = winPtr->display; + event.xmap.event = winPtr->window; + event.xmap.window = winPtr->window; + event.xmap.override_redirect = winPtr->atts.override_redirect; + Tk_HandleEvent(&event); + } } /* @@ -1900,8 +1902,9 @@ Tk_UnmapWindow( return; } winPtr->flags &= ~TK_MAPPED; - XUnmapWindow(winPtr->display, winPtr->window); - if (!(winPtr->flags & TK_TOP_HIERARCHY)) { + if ((winPtr->window != None) + && (XUnmapWindow(winPtr->display, winPtr->window) == Success) + && !(winPtr->flags & TK_TOP_HIERARCHY)) { XEvent event; event.type = UnmapNotify; diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index c950877..fb71a0c 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -128,7 +128,7 @@ XDestroyWindow( * Tk_WmMapWindow. * * Results: - * Returns Success or BadWindow. + * Always returns Success or BadWindow. * * Side effects: * The subwindow or toplevel may appear on the screen. VisibilityNotify diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 858ac34..93baa2d 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -874,18 +874,20 @@ TkWmUnmapWindow( TkWindow *winPtr) /* Top-level window that's about to be * unmapped. */ { - XEvent event; - - event.xany.serial = LastKnownRequestProcessed(winPtr->display); - event.xany.send_event = False; - event.xany.display = winPtr->display; - event.xunmap.type = UnmapNotify; - event.xunmap.window = winPtr->window; - event.xunmap.event = winPtr->window; - event.xunmap.from_configure = false; winPtr->flags &= ~TK_MAPPED; - XUnmapWindow(winPtr->display, winPtr->window); - Tk_HandleEvent(&event); + if ((winPtr->window != None) + && (XUnmapWindow(winPtr->display, winPtr->window) == Success)) { + XEvent event; + + event.xany.serial = LastKnownRequestProcessed(winPtr->display); + event.xany.send_event = False; + event.xany.display = winPtr->display; + event.xunmap.type = UnmapNotify; + event.xunmap.window = winPtr->window; + event.xunmap.event = winPtr->window; + event.xunmap.from_configure = false; + Tk_HandleEvent(&event); + } } /* diff --git a/win/tkWinWindow.c b/win/tkWinWindow.c index b85d59d..da92ee8 100644 --- a/win/tkWinWindow.c +++ b/win/tkWinWindow.c @@ -340,7 +340,7 @@ XDestroyWindow( * Cause the given window to become visible. * * Results: - * None + * Always returns Success or BadWindow. * * Side effects: * Causes the window state to change, and generates a MapNotify event. @@ -355,8 +355,12 @@ XMapWindow( { XEvent event; TkWindow *parentPtr; - TkWindow *winPtr = TkWinGetWinPtr(w); + TkWindow *winPtr; + if (!w) { + return BadWindow; + } + winPtr = TkWinGetWinPtr(w); LastKnownRequestProcessed(display)++; ShowWindow(Tk_GetHWND(w), SW_SHOWNORMAL); @@ -449,7 +453,7 @@ NotifyVisibility( * Cause the given window to become invisible. * * Results: - * None + * Always returns Success or BadWindow. * * Side effects: * Causes the window state to change, and generates an UnmapNotify event. @@ -463,8 +467,12 @@ XUnmapWindow( Window w) { XEvent event; - TkWindow *winPtr = TkWinGetWinPtr(w); + TkWindow *winPtr; + if (!w) { + return BadWindow; + } + winPtr = TkWinGetWinPtr(w); LastKnownRequestProcessed(display)++; /* -- cgit v0.12