From ac7e40cde23515da06683b2b0d4e61107bab8126 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 20 Feb 2014 00:32:39 +0000 Subject: [PATCH] Don't use invalid pointer in file dialog hook procedure in wxMSW. We can receive WM_NOTIFY for other than CDN_XXX messages if we have a native control as our immediate child (which can happen with "extra" controls) and the LPARAM is not a pointer to OFNOTIFY at all in this case, so don't try to use it as such. This fixes a crash when adding a "bare" extra control, see #16003. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75941 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/filedlg.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index 7327c7bdd7..15db452bae 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -172,22 +172,26 @@ wxFileDialogHookFunction(HWND hDlg, case WM_NOTIFY: { - OFNOTIFY* const - pNotifyCode = reinterpret_cast(lParam); - wxFileDialog* const - dialog = reinterpret_cast( - pNotifyCode->lpOFN->lCustData - ); - - switch ( pNotifyCode->hdr.code ) + NMHDR* const pNM = reinterpret_cast(lParam); + if ( pNM->code >= CDN_FIRST && pNM->code < CDN_LAST ) { - case CDN_INITDONE: - dialog->MSWOnInitDone((WXHWND)hDlg); - break; + OFNOTIFY* const + pNotifyCode = reinterpret_cast(lParam); + wxFileDialog* const + dialog = reinterpret_cast( + pNotifyCode->lpOFN->lCustData + ); - case CDN_SELCHANGE: - dialog->MSWOnSelChange((WXHWND)hDlg); - break; + switch ( pNotifyCode->hdr.code ) + { + case CDN_INITDONE: + dialog->MSWOnInitDone((WXHWND)hDlg); + break; + + case CDN_SELCHANGE: + dialog->MSWOnSelChange((WXHWND)hDlg); + break; + } } } break;