From 6640969f1fe43d8f172a29732275a6902013a4ea Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Sat, 22 Dec 2007 20:33:11 +0000 Subject: [PATCH] Fixing smaller bugs in ddraw.dll GetCaps 1. GetCaps should not call get avail memory for hel 2. add ddcaps size check 3. add Enter/leave CriticalSection GetDeviceIdentifier 1. add Enter/leave CriticalSection svn path=/trunk/; revision=31402 --- reactos/dll/directx/ddraw/Ddraw/GetCaps.c | 39 ++++++++++++++++--- .../directx/ddraw/Ddraw/GetDeviceIdentifier.c | 3 ++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/reactos/dll/directx/ddraw/Ddraw/GetCaps.c b/reactos/dll/directx/ddraw/Ddraw/GetCaps.c index 751fc9569c7..21e52b15d38 100644 --- a/reactos/dll/directx/ddraw/Ddraw/GetCaps.c +++ b/reactos/dll/directx/ddraw/Ddraw/GetCaps.c @@ -32,7 +32,9 @@ Main_DirectDraw_GetCaps( LPDDRAWI_DIRECTDRAW_INT This, LPDDCAPS pDriverCaps, DX_WINDBG_trace(); - _SEH_TRY + EnterCriticalSection( &ddcs ); + + _SEH_TRY { if ((!pDriverCaps) && (!pHELCaps)) { @@ -40,6 +42,34 @@ Main_DirectDraw_GetCaps( LPDDRAWI_DIRECTDRAW_INT This, LPDDCAPS pDriverCaps, _SEH_LEAVE; } + /* + * DDCAPS_DX6 and DDCAPS_DX7 have same size so + * we do not need check both only one of them + */ + if ( (pDriverCaps) && + (pDriverCaps->dwSize != sizeof(DDCAPS_DX1) ) && + (pDriverCaps->dwSize != sizeof(DDCAPS_DX3) ) && + (pDriverCaps->dwSize != sizeof(DDCAPS_DX5) ) && + (pDriverCaps->dwSize != sizeof(DDCAPS_DX7 )) ) + { + retVal = DDERR_INVALIDPARAMS; + _SEH_LEAVE; + } + + /* + * DDCAPS_DX6 and DDCAPS_DX7 have same size so + * we do not need check both only one of them + */ + if ( (pHELCaps) && + (pHELCaps->dwSize != sizeof(DDCAPS_DX1) ) && + (pHELCaps->dwSize != sizeof(DDCAPS_DX3) ) && + (pHELCaps->dwSize != sizeof(DDCAPS_DX5) ) && + (pHELCaps->dwSize != sizeof(DDCAPS_DX7 )) ) + { + retVal = DDERR_INVALIDPARAMS; + _SEH_LEAVE; + } + if (pDriverCaps) { /* Setup hardware caps */ @@ -153,14 +183,11 @@ Main_DirectDraw_GetCaps( LPDDRAWI_DIRECTDRAW_INT This, LPDDCAPS pDriverCaps, if (pHELCaps) { /* Setup software caps */ - DDSCAPS2 ddscaps = { 0 }; LPDDCORECAPS CoreCaps = (LPDDCORECAPS)&This->lpLcl->lpGbl->ddHELCaps; DWORD dwTotal = 0; DWORD dwFree = 0; - Main_DirectDraw_GetAvailableVidMem4(This, &ddscaps, &dwTotal, &dwFree); - switch (pHELCaps->dwSize) { case sizeof(DDCAPS_DX1): @@ -260,7 +287,6 @@ Main_DirectDraw_GetCaps( LPDDRAWI_DIRECTDRAW_INT This, LPDDCAPS pDriverCaps, } } - } _SEH_HANDLE { @@ -268,6 +294,7 @@ Main_DirectDraw_GetCaps( LPDDRAWI_DIRECTDRAW_INT This, LPDDCAPS pDriverCaps, } _SEH_END; - return retVal; + LeaveCriticalSection( &ddcs ); + return retVal; } diff --git a/reactos/dll/directx/ddraw/Ddraw/GetDeviceIdentifier.c b/reactos/dll/directx/ddraw/Ddraw/GetDeviceIdentifier.c index 0b4e88ae5c0..5d97a957101 100644 --- a/reactos/dll/directx/ddraw/Ddraw/GetDeviceIdentifier.c +++ b/reactos/dll/directx/ddraw/Ddraw/GetDeviceIdentifier.c @@ -75,6 +75,8 @@ Main_DirectDraw_GetDeviceIdentifier7(LPDDRAWI_DIRECTDRAW_INT This, DX_WINDBG_trace(); + EnterCriticalSection( &ddcs ); + _SEH_TRY { if ( (IsBadWritePtr( pDDDI, sizeof(DDDEVICEIDENTIFIER2) ) ) || @@ -184,5 +186,6 @@ Main_DirectDraw_GetDeviceIdentifier7(LPDDRAWI_DIRECTDRAW_INT This, } _SEH_END; + LeaveCriticalSection( &ddcs ); return retVal; }