Skip to content

Commit

Permalink
Validate window pointer before sending events for it
Browse files Browse the repository at this point in the history
If there are bugs it's possible that the window pointer is invalid. Double check it before sending the application events and potentially dereferencing it.

This showed up in #10494 as a window getting mouse focus as it was being destroyed and then crashing later when mouse focus was set to a different window.
  • Loading branch information
slouken committed Aug 7, 2024
1 parent 91d97a3 commit 9493e69
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/events/SDL_windowevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent,
{
int posted;

if (!window) {
if (!SDL_ObjectValid(window, SDL_OBJECT_TYPE_WINDOW)) {

This comment has been minimized.

Copy link
@madebr

madebr Aug 7, 2024

Contributor

Won't this hide bugs?

This comment has been minimized.

Copy link
@slouken

slouken Aug 7, 2024

Author Collaborator

Maybe? We could assert instead...

This comment has been minimized.

Copy link
@madebr

madebr Aug 7, 2024

Contributor

If I read the commit message correctly, you added this as a precaution and is not a fix.
If so, I'd prefer a loud assertion, but you're the boss :)

This comment has been minimized.

Copy link
@slouken

slouken Aug 7, 2024

Author Collaborator

I like where you're going with this. I'm heads down in some other stuff, so if you want to change it back to a NULL check and then add an assertion afterwards, that's fine.

return 0;
}
if (window->is_destroying && windowevent != SDL_EVENT_WINDOW_DESTROYED) {
Expand Down

0 comments on commit 9493e69

Please sign in to comment.