-
Notifications
You must be signed in to change notification settings - Fork 23
Potential null pointer dereference in Win32Window::WndProc #289 #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors Win32Window::WndProc to avoid a potential null pointer dereference by always returning DefWindowProc immediately after handling WM_NCCREATE and by guarding subsequent use of the window instance pointer with a null check. Sequence diagram for updated Win32Window::WndProc message handlingsequenceDiagram
participant OS
participant Win32Window_WndProc as Win32Window_WndProc
participant GetThisFromHandle
participant Win32Window_MessageHandler as Win32Window_MessageHandler
participant DefWindowProc
OS->>Win32Window_WndProc: WndProc(window, message, wparam, lparam)
alt message is WM_NCCREATE
Win32Window_WndProc->>OS: Get CREATESTRUCT and lpCreateParams
OS-->>Win32Window_WndProc: CREATESTRUCT with Win32Window pointer
Win32Window_WndProc->>Win32Window_WndProc: EnableFullDpiSupportIfAvailable(window)
Win32Window_WndProc->>Win32Window_WndProc: set window_handle_
Win32Window_WndProc->>DefWindowProc: DefWindowProc(window, message, wparam, lparam)
DefWindowProc-->>OS: LRESULT
else any other message
Win32Window_WndProc->>GetThisFromHandle: GetThisFromHandle(window)
GetThisFromHandle-->>Win32Window_WndProc: Win32Window pointer or null
alt Win32Window pointer not null
Win32Window_WndProc->>Win32Window_MessageHandler: MessageHandler(window, message, wparam, lparam)
Win32Window_MessageHandler-->>OS: LRESULT
else Win32Window pointer is null
Win32Window_WndProc-->>OS: 0 or default LRESULT
end
end
Class diagram for Win32Window with updated WndProc behaviorclassDiagram
class Win32Window {
HWND window_handle_
+static LRESULT CALLBACK WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
+LRESULT MessageHandler(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
+static Win32Window* GetThisFromHandle(HWND window)
+static void EnableFullDpiSupportIfAvailable(HWND window)
}
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The potential null dereference still exists in the WM_NCCREATE path:
thatis used without checking whetherwindow_struct->lpCreateParams(and thusthat) is non-null before assigningthat->window_handle_, so consider adding a null check or early return before dereferencing.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The potential null dereference still exists in the WM_NCCREATE path: `that` is used without checking whether `window_struct->lpCreateParams` (and thus `that`) is non-null before assigning `that->window_handle_`, so consider adding a null check or early return before dereferencing.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
Bug Fixes: