From 86d7bcb124e669e6de56c7208e6f3592d852819a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 19 Jan 2024 13:07:12 +0100 Subject: [PATCH] Fix missing checks for platform mismatch The native access functions for monitor objects did not check whether the correct platform was initialized and would return invalid handles if it was not. --- src/cocoa_monitor.m | 7 +++++++ src/win32_monitor.c | 14 ++++++++++++++ src/wl_monitor.c | 7 +++++++ src/x11_monitor.c | 14 ++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 78089419..e351088a 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -622,6 +622,13 @@ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(kCGNullDirectDisplay); + + if (_glfw.platform.platformID != GLFW_PLATFORM_COCOA) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Cocoa: Platform not initialized"); + return kCGNullDirectDisplay; + } + return monitor->ns.displayID; } diff --git a/src/win32_monitor.c b/src/win32_monitor.c index 13f7bfe7..4edaf2c3 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -535,6 +535,13 @@ GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + if (_glfw.platform.platformID != GLFW_PLATFORM_WIN32) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Win32: Platform not initialized"); + return NULL; + } + return monitor->win32.publicAdapterName; } @@ -542,6 +549,13 @@ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + if (_glfw.platform.platformID != GLFW_PLATFORM_WIN32) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Win32: Platform not initialized"); + return NULL; + } + return monitor->win32.publicDisplayName; } diff --git a/src/wl_monitor.c b/src/wl_monitor.c index df64f603..96527a48 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -259,6 +259,13 @@ GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + if (_glfw.platform.platformID != GLFW_PLATFORM_WAYLAND) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Wayland: Platform not initialized"); + return NULL; + } + return monitor->wl.output; } diff --git a/src/x11_monitor.c b/src/x11_monitor.c index ae626643..31640fb1 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -604,6 +604,13 @@ GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(None); + + if (_glfw.platform.platformID != GLFW_PLATFORM_X11) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized"); + return None; + } + return monitor->x11.crtc; } @@ -611,6 +618,13 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; _GLFW_REQUIRE_INIT_OR_RETURN(None); + + if (_glfw.platform.platformID != GLFW_PLATFORM_X11) + { + _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "X11: Platform not initialized"); + return None; + } + return monitor->x11.output; }