From 0f47d3a77be2b7e303e6911c38af5c10e07df72b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 6 Oct 2024 08:34:35 -0700 Subject: [PATCH] Fixed use after free (thanks @meyraud705!) Fixes https://github.com/libsdl-org/SDL/issues/11090 --- test/testwm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/testwm.c b/test/testwm.c index c92cd98bbc..3315aea381 100644 --- a/test/testwm.c +++ b/test/testwm.c @@ -47,7 +47,7 @@ SDL_COMPILE_TIME_ASSERT(cursorNames, SDL_arraysize(cursorNames) == SDL_SYSTEM_CU static int system_cursor = -1; static SDL_Cursor *cursor = NULL; -static const SDL_DisplayMode *highlighted_mode = NULL; +static SDL_DisplayMode highlighted_mode; /* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */ static void @@ -95,7 +95,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport) /* Clear the cached mode under the mouse */ if (window == SDL_GetMouseFocus()) { - highlighted_mode = NULL; + SDL_zero(highlighted_mode); } displays = SDL_GetDisplays(NULL); @@ -126,7 +126,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport) /* Update cached mode under the mouse */ if (window == SDL_GetMouseFocus()) { - highlighted_mode = mode; + SDL_copyp(&highlighted_mode, mode); } } else { SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255); @@ -213,9 +213,9 @@ static void loop(void) } if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) { SDL_Window *window = SDL_GetMouseFocus(); - if (highlighted_mode && window) { - SDL_memcpy(&state->fullscreen_mode, highlighted_mode, sizeof(state->fullscreen_mode)); - SDL_SetWindowFullscreenMode(window, highlighted_mode); + if (highlighted_mode.w && window) { + SDL_copyp(&state->fullscreen_mode, &highlighted_mode, sizeof(state->fullscreen_mode)); + SDL_SetWindowFullscreenMode(window, &highlighted_mode); } } }