From 5b9f91c18d7e21ecdd1dfb662682c34cd143d4c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20D=C3=B6singer?= Date: Wed, 16 Jul 2014 14:39:10 +0200 Subject: [PATCH] ddraw: Add validation to SetPriority / GetPriority. --- dlls/ddraw/surface.c | 72 +++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index 3d61e61312d..355a88b8229 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -2229,63 +2229,59 @@ static HRESULT WINAPI ddraw_surface1_GetCaps(IDirectDrawSurface *iface, DDSCAPS return hr; } -/***************************************************************************** - * IDirectDrawSurface7::SetPriority - * - * Sets a texture priority for managed textures. - * - * Params: - * Priority: The new priority - * - * Returns: - * DD_OK on success - * For more details, see IWineD3DSurface::SetPriority - * - *****************************************************************************/ -static HRESULT WINAPI ddraw_surface7_SetPriority(IDirectDrawSurface7 *iface, DWORD Priority) +static HRESULT WINAPI ddraw_surface7_SetPriority(IDirectDrawSurface7 *iface, DWORD priority) { struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface); + DWORD managed = DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE; HRESULT hr; - TRACE("iface %p, priority %u.\n", iface, Priority); + TRACE("iface %p, priority %u.\n", iface, priority); wined3d_mutex_lock(); - hr = wined3d_surface_set_priority(surface->wined3d_surface, Priority); + /* No need to check for offscreen plain surfaces or mipmap sublevels. SetPriority + * calls on such surfaces segfault on Windows. */ + if (!(surface->surface_desc.ddsCaps.dwCaps2 & managed)) + { + WARN("Called on non-managed texture returning DDERR_INVALIDPARAMS.\n"); + hr = DDERR_INVALIDPARAMS; + } + else + { + wined3d_surface_set_priority(surface->wined3d_surface, priority); + hr = DD_OK; + } wined3d_mutex_unlock(); return hr; } -/***************************************************************************** - * IDirectDrawSurface7::GetPriority - * - * Returns the surface's priority - * - * Params: - * Priority: Address of a variable to write the priority to - * - * Returns: - * D3D_OK on success - * DDERR_INVALIDPARAMS if Priority == NULL - * For more details, see IWineD3DSurface::GetPriority - * - *****************************************************************************/ -static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWORD *Priority) +static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWORD *priority) { struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface); + DWORD managed = DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE; + HRESULT hr; - TRACE("iface %p, priority %p.\n", iface, Priority); + TRACE("iface %p, priority %p.\n", iface, priority); - if(!Priority) + wined3d_mutex_lock(); + if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_OFFSCREENPLAIN) { - return DDERR_INVALIDPARAMS; + WARN("Called on offscreenplain surface, returning DDERR_INVALIDOBJECT.\n"); + hr = DDERR_INVALIDOBJECT; + } + else if (!(surface->surface_desc.ddsCaps.dwCaps2 & managed) || !surface->wined3d_texture) + { + WARN("Called on non-managed texture or mipmap sublevel, returning DDERR_INVALIDPARAMS.\n"); + hr = DDERR_INVALIDPARAMS; + } + else + { + *priority = wined3d_surface_get_priority(surface->wined3d_surface); + hr = DD_OK; } - - wined3d_mutex_lock(); - *Priority = wined3d_surface_get_priority(surface->wined3d_surface); wined3d_mutex_unlock(); - return DD_OK; + return hr; } /***************************************************************************** -- 2.11.4.GIT