[PATCH v3 1/4] ddraw: Don't crash if writing out a new ddraw1 surface segfaults.
Alex Henrie
alexhenrie24 at gmail.com
Sat Jan 28 15:59:13 CST 2017
Fixes https://bugs.winehq.org/show_bug.cgi?id=42159
Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
dlls/ddraw/ddraw.c | 19 +++++++++++++++----
dlls/ddraw/tests/ddraw1.c | 2 ++
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index e313a7500e..2375df2250 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -26,6 +26,8 @@
#include "ddraw_private.h"
+#include "wine/exception.h"
+
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
static const struct ddraw *exclusive_ddraw;
@@ -2974,13 +2976,22 @@ static HRESULT WINAPI ddraw1_CreateSurface(IDirectDraw *iface,
DDSD_to_DDSD2(surface_desc, &surface_desc2);
hr = ddraw_surface_create(ddraw, &surface_desc2, &impl, outer_unknown, 1);
wined3d_mutex_unlock();
- if (FAILED(hr))
+
+ __TRY
{
- *surface = NULL;
- return hr;
+ if (FAILED(hr))
+ {
+ *surface = NULL;
+ return hr;
+ }
+ *surface = &impl->IDirectDrawSurface_iface;
+ }
+ __EXCEPT_PAGE_FAULT
+ {
+ return E_INVALIDARG;
}
+ __ENDTRY;
- *surface = &impl->IDirectDrawSurface_iface;
impl->ifaceToRelease = NULL;
return hr;
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index ed4c5ec493..ff88b74a28 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -1967,6 +1967,8 @@ static void test_surface_qi(void)
surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
surface_desc.dwWidth = 512;
surface_desc.dwHeight = 512;
+ hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface **)0xdeadbeef, NULL);
+ ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
--
2.11.0
More information about the wine-patches
mailing list