ddraw: Add checking of SURFACEDESC type/nullness into CreateSurface methods.

This commit is contained in:
Oldřich Jedlička 2010-09-17 07:31:26 +02:00 committed by Alexandre Julliard
parent b94bc5604a
commit a6c3d0d6ac
2 changed files with 54 additions and 12 deletions

View File

@ -3311,6 +3311,12 @@ static HRESULT WINAPI ddraw7_CreateSurface(IDirectDraw7 *iface,
TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n", TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
iface, surface_desc, surface, outer_unknown); 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(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER))
{ {
if (TRACE_ON(ddraw)) 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", TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
iface, surface_desc, surface, outer_unknown); 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(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER))
{ {
if (TRACE_ON(ddraw)) 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", TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
iface, surface_desc, surface, outer_unknown); 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(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER))
{ {
if (TRACE_ON(ddraw)) 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", TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
iface, surface_desc, surface, outer_unknown); 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(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER))
{ {
if (TRACE_ON(ddraw)) 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", TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
iface, surface_desc, surface, outer_unknown); 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 /* Remove front buffer flag, this causes failure in v7, and its added to normal
* primaries anyway. */ * primaries anyway. */
surface_desc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER; surface_desc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;

View File

@ -3638,16 +3638,19 @@ static void CreateSurfaceBadCapsSizeTest(void)
IDirectDrawSurface_Release(surf); IDirectDrawSurface_Release(surf);
hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad1, &surf, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad2, &surf, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad3, &surf, NULL); hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad3, &surf, NULL);
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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw_CreateSurface(lpDD, &ddsd_bad4, &surf, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2); hr = IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw2, (void **) &dd2);
@ -3658,16 +3661,19 @@ static void CreateSurfaceBadCapsSizeTest(void)
IDirectDrawSurface_Release(surf); IDirectDrawSurface_Release(surf);
hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad1, &surf, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad2, &surf, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad3, &surf, NULL); hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad3, &surf, NULL);
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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw2_CreateSurface(dd2, &ddsd_bad4, &surf, NULL); 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); DDERR_INVALIDPARAMS, hr);
IDirectDraw2_Release(dd2); IDirectDraw2_Release(dd2);
@ -3680,16 +3686,19 @@ static void CreateSurfaceBadCapsSizeTest(void)
IDirectDrawSurface4_Release(surf4); IDirectDrawSurface4_Release(surf4);
hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad1, &surf4, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad2, &surf4, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad3, &surf4, NULL); hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad3, &surf4, NULL);
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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw4_CreateSurface(dd4, &ddsd2_bad4, &surf4, NULL); 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); DDERR_INVALIDPARAMS, hr);
IDirectDraw4_Release(dd4); IDirectDraw4_Release(dd4);
@ -3702,16 +3711,19 @@ static void CreateSurfaceBadCapsSizeTest(void)
IDirectDrawSurface7_Release(surf7); IDirectDrawSurface7_Release(surf7);
hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad1, &surf7, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad2, &surf7, NULL); 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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad3, &surf7, NULL); hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad3, &surf7, NULL);
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); DDERR_INVALIDPARAMS, hr);
hr = IDirectDraw7_CreateSurface(dd7, &ddsd2_bad4, &surf7, NULL); 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); DDERR_INVALIDPARAMS, hr);
IDirectDraw7_Release(dd7); IDirectDraw7_Release(dd7);