From a6c3d0d6ac2f071a673744f7472975845f073295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Old=C5=99ich=20Jedli=C4=8Dka?= Date: Fri, 17 Sep 2010 07:31:26 +0200 Subject: [PATCH] ddraw: Add checking of SURFACEDESC type/nullness into CreateSurface methods. --- dlls/ddraw/ddraw.c | 30 ++++++++++++++++++++++++++++++ dlls/ddraw/tests/dsurface.c | 36 ++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index 5449d841e2b..755214497e6 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -3311,6 +3311,12 @@ static HRESULT WINAPI ddraw7_CreateSurface(IDirectDraw7 *iface, TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC2)) + { + WARN("Application supplied invalid surface descriptor\n"); + return DDERR_INVALIDPARAMS; + } + if(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER)) { if (TRACE_ON(ddraw)) @@ -3336,6 +3342,12 @@ static HRESULT WINAPI ddraw4_CreateSurface(IDirectDraw4 *iface, TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC2)) + { + WARN("Application supplied invalid surface descriptor\n"); + return DDERR_INVALIDPARAMS; + } + if(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER)) { if (TRACE_ON(ddraw)) @@ -3372,6 +3384,12 @@ static HRESULT WINAPI ddraw3_CreateSurface(IDirectDraw3 *iface, TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC)) + { + WARN("Application supplied invalid surface descriptor\n"); + return DDERR_INVALIDPARAMS; + } + if(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER)) { if (TRACE_ON(ddraw)) @@ -3412,6 +3430,12 @@ static HRESULT WINAPI ddraw2_CreateSurface(IDirectDraw2 *iface, TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC)) + { + WARN("Application supplied invalid surface descriptor\n"); + return DDERR_INVALIDPARAMS; + } + if(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER)) { if (TRACE_ON(ddraw)) @@ -3451,6 +3475,12 @@ static HRESULT WINAPI ddraw1_CreateSurface(IDirectDraw *iface, TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", iface, surface_desc, surface, outer_unknown); + if(surface_desc == NULL || surface_desc->dwSize != sizeof(DDSURFACEDESC)) + { + WARN("Application supplied invalid surface descriptor\n"); + return DDERR_INVALIDPARAMS; + } + /* Remove front buffer flag, this causes failure in v7, and its added to normal * primaries anyway. */ surface_desc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER; diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c index 1c219a47418..93934e528cf 100644 --- a/dlls/ddraw/tests/dsurface.c +++ b/dlls/ddraw/tests/dsurface.c @@ -3638,16 +3638,19 @@ static void CreateSurfaceBadCapsSizeTest(void) IDirectDrawSurface_Release(surf); hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad1, &surf, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad2, &surf, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad3, &surf, NULL); ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad4, &surf, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n", + DDERR_INVALIDPARAMS, hr); + hr = IDirectDraw_CreateSurface(lpDD, NULL, &surf, NULL); + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2); @@ -3658,16 +3661,19 @@ static void CreateSurfaceBadCapsSizeTest(void) IDirectDrawSurface_Release(surf); hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad1, &surf, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad2, &surf, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad3, &surf, NULL); ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad4, &surf, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n", + DDERR_INVALIDPARAMS, hr); + hr = IDirectDraw2_CreateSurface(dd2, NULL, &surf, NULL); + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw2_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); IDirectDraw2_Release(dd2); @@ -3680,16 +3686,19 @@ static void CreateSurfaceBadCapsSizeTest(void) IDirectDrawSurface4_Release(surf4); hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad1, &surf4, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad2, &surf4, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad3, &surf4, NULL); ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad4, &surf4, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n", + DDERR_INVALIDPARAMS, hr); + hr = IDirectDraw4_CreateSurface(dd4, NULL, &surf4, NULL); + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw4_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); IDirectDraw4_Release(dd4); @@ -3702,16 +3711,19 @@ static void CreateSurfaceBadCapsSizeTest(void) IDirectDrawSurface7_Release(surf7); hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad1, &surf7, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad2, &surf7, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad3, &surf7, NULL); ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad4, &surf7, NULL); - todo_wine ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n", + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n", + DDERR_INVALIDPARAMS, hr); + hr = IDirectDraw7_CreateSurface(dd7, NULL, &surf7, NULL); + ok(hr == DDERR_INVALIDPARAMS, "IDirectDraw7_CreateSurface didn't return 0x%08x, but 0x%08x\n", DDERR_INVALIDPARAMS, hr); IDirectDraw7_Release(dd7);