Fix joystick crash when a button guid is specified in the data

format.
Add some parameter checking.
This commit is contained in:
Robert Reif 2005-05-10 13:17:03 +00:00 committed by Alexandre Julliard
parent 7464134919
commit 2095f66d44
3 changed files with 40 additions and 8 deletions

View File

@ -313,6 +313,7 @@ DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT a
* 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 DIDATAFORMAT *wine_format, LPCDIDATAFORMAT a
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;

View File

@ -331,6 +331,16 @@ static HRESULT WINAPI IDirectInputAImpl_CreateDevice(
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;

View File

@ -713,6 +713,16 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat(
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_SetProperty(
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_GetCapabilities(
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;