Skip to content

Potential null pointer dereference in Win32Window::WndProc #289

@g-k-s-03

Description

@g-k-s-03

Description:
In win32_window.cpp.cpp, the WndProc function relies on WM_NCCREATE to set the GWLP_USERDATA pointer to the Win32Window instance. Later messages call GetThisFromHandle(window), which dereferences this pointer:

else if (Win32Window* that = GetThisFromHandle(window)) {
return that->MessageHandler(window, message, wparam, lparam);
}

Potential Issue:
If a message arrives before WM_NCCREATE is processed, GWLP_USERDATA will be nullptr. This can result in undefined behaviour or a crash when dereferencing the pointer. This could happen in rare circumstances, depending on the Windows message queue timing.

Suggested Fix:

Safely check if GetThisFromHandle(window) returns nullptr before dereferencing.

Example:

Win32Window* that = GetThisFromHandle(window);
if (that) {
return that->MessageHandler(window, message, wparam, lparam);
}

This ensures the window procedure does not attempt to access an uninitialized pointer.

Severity: Critical – could crash the app.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions