riched20: Handle incorrect calls of window procedure (bug 4452)

Krzysztof Foltman wdev at foltman.com
Wed Aug 2 15:54:03 CDT 2006


This is an another incarnation of the infamous NULL pointer check which 
was posted in different versions by different people and rejected 
gazillion times for various reasons.

Also included is a tiny fix of the temporary debug key combination 
Ctrl+W. It isn't meant to be used by anyone except developers, yet it 
could previously cause crashes when pressed by accident.

Krzysztof


-------------- next part --------------
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 390ac3b..5b42584 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1060,6 +1060,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD n
         {
           CHARFORMAT2W chf;
           char buf[2048];
+          chf.cbSize = sizeof(chf);
           
           ME_GetSelectionCharFormat(editor, &chf);
           ME_DumpStyleToBuf(&chf, buf);
@@ -1393,11 +1394,16 @@ get_msg_name(UINT msg)
  */
 LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
   SCROLLINFO si;
-  ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
+  ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0);
   
   TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
         hWnd, msg, get_msg_name(msg), wParam, lParam);
   
+  if (!editor && msg != WM_NCCREATE && msg != WM_NCDESTROY) {
+    ERR("RichEditANSIWndProc called with invalid hWnd %p - application bug?\n", hWnd);
+    return 0; 
+  }
+
   switch(msg) {
   
   UNSUPPORTED_MSG(EM_DISPLAYBAND)


More information about the wine-patches mailing list