Making Wine WNDPROC handlers check HWND argument

Jukka Heinonen jhei at iki.fi
Fri Jul 20 20:17:04 CDT 2001


Wine WNDPROC handlers did not check HWND argument and thus
invalid handles caused these handlers to crash. Windows
handlers have this check so Wine handlers should also have it.
At least DeusEx seems to rely on this behaviour.

File combo.c was modified only for consistency and readability.
Reason why I considered this necessary is seen in the patch for 
listbox.c.

Changelog:
  WNDPROC handlers now check whether HWND argument is valid.

Index: wine/controls/button.c
===================================================================
RCS file: /home/wine/wine/controls/button.c,v
retrieving revision 1.49
diff -u -r1.49 button.c
--- wine/controls/button.c      2001/02/23 01:32:05     1.49
+++ wine/controls/button.c      2001/07/21 00:56:59
@@ -407,10 +407,11 @@
  */
 static LRESULT WINAPI ButtonWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
 {
-    LRESULT res;
+    LRESULT res = 0;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
 
-    res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam,TRUE);
+    if( wndPtr )
+        res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam,TRUE);
 
     WIN_ReleaseWndPtr(wndPtr);
     return res;
@@ -422,10 +423,11 @@
  */
 static LRESULT WINAPI ButtonWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
 {
-    LRESULT res;
+    LRESULT res = 0;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
 
-    res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam,FALSE);
+    if( wndPtr )
+        res = ButtonWndProc_locked(wndPtr,uMsg,wParam,lParam,FALSE);
 
     WIN_ReleaseWndPtr(wndPtr);
     return res;

Index: wine/controls/static.c
===================================================================
RCS file: /home/wine/wine/controls/static.c,v
retrieving revision 1.28
diff -u -r1.28 static.c
--- wine/controls/static.c      2001/03/10 19:16:26     1.28
+++ wine/controls/static.c      2001/07/21 00:59:51
@@ -356,10 +356,11 @@
  */
 static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
 {
-    LRESULT lResult;
+    LRESULT lResult = 0;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
 
-    lResult = StaticWndProc_locked(wndPtr, uMsg, wParam, lParam, FALSE);
+    if( wndPtr )
+        lResult = StaticWndProc_locked(wndPtr, uMsg, wParam, lParam, FALSE);
 
     WIN_ReleaseWndPtr(wndPtr);
     return lResult;
@@ -370,10 +371,11 @@
  */
 static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
 {
-    LRESULT lResult;
+    LRESULT lResult = 0;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
 
-    lResult = StaticWndProc_locked(wndPtr, uMsg, wParam, lParam, TRUE);
+    if( wndPtr )
+        lResult = StaticWndProc_locked(wndPtr, uMsg, wParam, lParam, TRUE);
 
     WIN_ReleaseWndPtr(wndPtr);
     return lResult;

Index: wine/controls/edit.c
===================================================================
RCS file: /home/wine/wine/controls/edit.c,v
retrieving revision 1.84
diff -u -r1.84 edit.c
--- wine/controls/edit.c        2001/07/11 17:26:33     1.84
+++ wine/controls/edit.c        2001/07/21 01:00:21
@@ -1121,10 +1121,11 @@
  */
 LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
-    LRESULT res;
+    LRESULT res = 0;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
 
-    res = EditWndProc_locked(wndPtr, uMsg, wParam, lParam, TRUE);
+    if( wndPtr )
+        res = EditWndProc_locked(wndPtr, uMsg, wParam, lParam, TRUE);
 
     WIN_ReleaseWndPtr(wndPtr);
     return res;
@@ -1136,10 +1137,11 @@
  */
 LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
-    LRESULT res;
+    LRESULT res = 0;
     WND *wndPtr = WIN_FindWndPtr(hWnd);
 
-    res = EditWndProc_locked(wndPtr, uMsg, wParam, lParam, FALSE);
+    if( wndPtr )
+        res = EditWndProc_locked(wndPtr, uMsg, wParam, lParam, FALSE);
 
     WIN_ReleaseWndPtr(wndPtr);
     return res;

Index: wine/controls/icontitle.c
===================================================================
RCS file: /home/wine/wine/controls/icontitle.c,v
retrieving revision 1.16
diff -u -r1.16 icontitle.c
--- wine/controls/icontitle.c   2000/12/19 04:53:20     1.16
+++ wine/controls/icontitle.c   2001/07/21 01:01:57
@@ -200,6 +200,9 @@
     LRESULT retvalue;
     WND *wnd = WIN_FindWndPtr( hWnd );
 
+    if( !wnd )
+      return 0;
+
     switch( msg )
     {
         case WM_CREATE:

Index: wine/controls/scroll.c
===================================================================
RCS file: /home/wine/wine/controls/scroll.c,v
retrieving revision 1.40
diff -u -r1.40 scroll.c
--- wine/controls/scroll.c      2001/06/22 23:21:47     1.40
+++ wine/controls/scroll.c      2001/07/21 01:02:35
@@ -1125,6 +1125,13 @@
  */
 static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
 {
+    WND *wndPtr = WIN_FindWndPtr( hwnd ); 
+
+    if( !wndPtr )
+        return 0;
+
+    WIN_ReleaseWndPtr( wndPtr );
+
     switch(message)
     {
     case WM_CREATE:

Index: wine/controls/listbox.c
===================================================================
RCS file: /home/wine/wine/controls/listbox.c,v
retrieving revision 1.76
diff -u -r1.76 listbox.c
--- wine/controls/listbox.c     2001/07/17 00:55:23     1.76
+++ wine/controls/listbox.c     2001/07/21 01:03:52
@@ -2466,7 +2466,6 @@
     LB_DESCR *descr;
     HWND       hwnd = wnd->hwndSelf;
 
-    if (!wnd) return 0;
     if (!(descr = *(LB_DESCR **)wnd->wExtra))
     {
         if (msg == WM_CREATE)
@@ -3022,9 +3021,12 @@
  */
 static LRESULT WINAPI ListBoxWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
 {
+    LRESULT     res = 0;
     WND*       wndPtr = WIN_FindWndPtr( hwnd );
-    LRESULT    res = ListBoxWndProc_locked(wndPtr, msg, wParam, lParam, FALSE);
 
+    if( wndPtr )
+        res = ListBoxWndProc_locked(wndPtr, msg, wParam, lParam, FALSE);
+
     WIN_ReleaseWndPtr(wndPtr);
     return res;
 }
@@ -3034,8 +3036,11 @@
  */
 static LRESULT WINAPI ListBoxWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
 {
+    LRESULT     res = 0;
     WND*       wndPtr = WIN_FindWndPtr( hwnd );
-    LRESULT    res = ListBoxWndProc_locked(wndPtr, msg, wParam, lParam, TRUE);
+
+    if( wndPtr )
+        res = ListBoxWndProc_locked(wndPtr, msg, wParam, lParam, TRUE);
 
     WIN_ReleaseWndPtr(wndPtr);
     return res;
@@ -3052,8 +3057,6 @@
     LRESULT lRet = 0;
     HWND hwnd;
 
-    if (wnd)
-    {
        LB_DESCR *descr = *(LB_DESCR **)wnd->wExtra;
 
         TRACE_(combo)("[%04x]: msg %s wp %08x lp %08lx\n",
@@ -3195,7 +3198,7 @@
                         DefWindowProcA( hwnd, msg, wParam, lParam );
 
         TRACE_(combo)("\t default on msg [%04x]\n", (UINT16)msg );
-    }
+
     return lRet;
 }
 
@@ -3211,8 +3214,11 @@
 LRESULT WINAPI ComboLBWndProcA( HWND hwnd, UINT msg,
                                WPARAM wParam, LPARAM lParam )
 {
+    LRESULT res = 0;
     WND *wnd = WIN_FindWndPtr( hwnd );
-    LRESULT res = ComboLBWndProc_locked(wnd, msg, wParam, lParam, FALSE);
+
+    if( wnd )
+        res = ComboLBWndProc_locked(wnd, msg, wParam, lParam, FALSE);
 
     WIN_ReleaseWndPtr(wnd);
     return res;
@@ -3223,8 +3229,11 @@
  */
 LRESULT WINAPI ComboLBWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
 {
+    LRESULT res = 0;
     WND *wnd = WIN_FindWndPtr( hwnd );
-    LRESULT res = ComboLBWndProc_locked(wnd, msg, wParam, lParam, TRUE);
+
+    if( wnd )
+        res = ComboLBWndProc_locked(wnd, msg, wParam, lParam, TRUE);
 
     WIN_ReleaseWndPtr(wnd);
     return res;

Index: wine/controls/combo.c
===================================================================
RCS file: /home/wine/wine/controls/combo.c,v
retrieving revision 1.72
diff -u -r1.72 combo.c
--- wine/controls/combo.c       2001/05/31 21:39:21     1.72
+++ wine/controls/combo.c       2001/07/21 01:08:50
@@ -1863,7 +1863,6 @@
 static LRESULT ComboWndProc_locked( WND* pWnd, UINT message,
                                     WPARAM wParam, LPARAM lParam, BOOL unicode )
 {
-    if( pWnd ) {
       LPHEADCOMBO      lphc = CB_GETPTR(pWnd);
       HWND             hwnd = pWnd->hwndSelf;
 
@@ -2255,8 +2254,6 @@
     }
     return unicode ? DefWindowProcW(hwnd, message, wParam, lParam) :
                     DefWindowProcA(hwnd, message, wParam, lParam);
-  }
-  return CB_ERR;
 }
 
 /***********************************************************************
@@ -2267,9 +2264,12 @@
  */
 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
 {
+    LRESULT retvalue = CB_ERR;
     WND*       pWnd = WIN_FindWndPtr(hwnd);
-    LRESULT retvalue = ComboWndProc_locked(pWnd, message, wParam, lParam, FALSE);
 
+    if( pWnd )
+        retvalue = ComboWndProc_locked(pWnd, message, wParam, lParam, FALSE);
+
     WIN_ReleaseWndPtr(pWnd);
     return retvalue;
 }
@@ -2279,8 +2279,11 @@
  */
 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
 {
+    LRESULT retvalue = CB_ERR;
     WND*       pWnd = WIN_FindWndPtr(hwnd);
-    LRESULT retvalue = ComboWndProc_locked(pWnd, message, wParam, lParam, TRUE);
+    
+    if( pWnd )
+        retvalue = ComboWndProc_locked(pWnd, message, wParam, lParam, TRUE);
 
     WIN_ReleaseWndPtr(pWnd);
     return retvalue;

-- 
Jukka Heinonen <http://www.iki.fi/jhei/>




More information about the wine-patches mailing list