[DINPUT] fix joystick crash and parameter checking

Robert Reif reif at earthlink.net
Tue May 10 06:35:16 CDT 2005


Fix joystick crash when a button guid is specified in the data format.
Add some parameter checking.
-------------- next part --------------
Index: dlls/dinput/device.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/device.c,v
retrieving revision 1.27
diff -u -p -r1.27 device.c
--- dlls/dinput/device.c	5 May 2005 09:49:54 -0000	1.27
+++ dlls/dinput/device.c	10 May 2005 11:29:15 -0000
@@ -313,6 +313,7 @@ DataFormat *create_DataFormat(const DIDA
 		 * the GUID of the Wine object.
 		 */
 		((asked_format->rgodf[j].pguid == NULL) ||
+		 (wine_format->rgodf[i].pguid == NULL) ||
 		 (IsEqualGUID(wine_format->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
 		&&
 		(/* Then check if it accepts any instance id, and if not, if it matches Wine's
@@ -336,19 +337,19 @@ DataFormat *create_DataFormat(const DIDA
 		TRACE("       * dwType: %08lx\n", asked_format->rgodf[j].dwType);
 		TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
 		
-		TRACE("   - Wine  (%d) :\n", j);
+		TRACE("   - Wine  (%d) :\n", i);
 		TRACE("       * GUID: %s ('%s')\n",
-		      debugstr_guid(wine_format->rgodf[j].pguid),
-		      _dump_dinput_GUID(wine_format->rgodf[j].pguid));
-		TRACE("       * Offset: %3ld\n", wine_format->rgodf[j].dwOfs);
-		TRACE("       * dwType: %08lx\n", wine_format->rgodf[j].dwType);
-		TRACE("         "); _dump_EnumObjects_flags(wine_format->rgodf[j].dwType); TRACE("\n");
+		      debugstr_guid(wine_format->rgodf[i].pguid),
+		      _dump_dinput_GUID(wine_format->rgodf[i].pguid));
+		TRACE("       * Offset: %3ld\n", wine_format->rgodf[i].dwOfs);
+		TRACE("       * dwType: %08lx\n", wine_format->rgodf[i].dwType);
+		TRACE("         "); _dump_EnumObjects_flags(wine_format->rgodf[i].dwType); TRACE("\n");
 		
 		if (wine_format->rgodf[i].dwType & DIDFT_BUTTON)
 		    dt[index].size = sizeof(BYTE);
 		else
 		    dt[index].size = sizeof(DWORD);
-		dt[index].offset_in  = wine_format ->rgodf[i].dwOfs;
+		dt[index].offset_in = wine_format->rgodf[i].dwOfs;
                 if (asked_format->rgodf[j].dwOfs < next) {
                     WARN("bad format: dwOfs=%ld, changing to %ld\n", asked_format->rgodf[j].dwOfs, next);
 		    dt[index].offset_out = next;
Index: dlls/dinput/dinput_main.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/dinput_main.c,v
retrieving revision 1.52
diff -u -p -r1.52 dinput_main.c
--- dlls/dinput/dinput_main.c	24 Mar 2005 21:01:39 -0000	1.52
+++ dlls/dinput/dinput_main.c	10 May 2005 11:29:16 -0000
@@ -331,6 +331,16 @@ static HRESULT WINAPI IDirectInputAImpl_
 
 	TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk);
 
+	if (pdev == NULL) {
+		WARN("invalid pointer: pdev == NULL\n");
+		return E_POINTER;
+	}
+
+	if (rguid == NULL) {
+		WARN("invalid pointer: rguid == NULL\n");
+		return E_POINTER;
+	}
+
 	/* Loop on all the devices to see if anyone matches the given GUID */
 	for (i = 0; i < NB_DINPUT_DEVICES; i++) {
 	  HRESULT ret;
Index: dlls/dinput/joystick_linux.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/joystick_linux.c,v
retrieving revision 1.23
diff -u -p -r1.23 joystick_linux.c
--- dlls/dinput/joystick_linux.c	15 Mar 2005 19:36:15 -0000	1.23
+++ dlls/dinput/joystick_linux.c	10 May 2005 11:29:17 -0000
@@ -713,6 +713,16 @@ static HRESULT WINAPI JoystickAImpl_SetD
 
     TRACE("(%p,%p)\n",This,df);
 
+    if (df == NULL) {
+        WARN("invalid pointer\n");
+        return E_POINTER;
+    }
+
+    if (df->dwSize != sizeof(*df)) {
+        WARN("invalid argument\n");
+        return DIERR_INVALIDPARAM;
+    }
+
     if (This->acquired) {
         WARN("acquired\n");
         return DIERR_ACQUIRED;
@@ -1113,6 +1123,11 @@ static HRESULT WINAPI JoystickAImpl_SetP
 
     TRACE("(%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
 
+    if (ph == NULL) {
+        WARN("invalid pointer\n");
+        return E_POINTER;
+    }
+
     if (TRACE_ON(dinput))
         _dump_DIPROPHEADER(ph);
 
@@ -1214,10 +1229,16 @@ static HRESULT WINAPI JoystickAImpl_GetC
 
     if (lpDIDevCaps == NULL) {
         WARN("invalid parameter: lpDIDevCaps = NULL\n");
-        return DIERR_INVALIDPARAM;
+        return E_POINTER;
     }
 
     size = lpDIDevCaps->dwSize;
+
+    if (!(size == sizeof(DIDEVCAPS) || size == sizeof(DIDEVCAPS_DX3))) {
+        WARN("invalid parameter\n");
+        return DIERR_INVALIDPARAM;
+    }
+
     CopyMemory(lpDIDevCaps, &This->devcaps, size);
     lpDIDevCaps->dwSize = size;
 


More information about the wine-patches mailing list