Alex Henrie : ddraw: Don' t crash if writing out a new ddraw2 surface segfaults.

Alexandre Julliard julliard at winehq.org
Mon Jan 30 15:39:17 CST 2017


Module: wine
Branch: master
Commit: f6997e8fe0563da811d1627034dd95ab3a8e10af
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f6997e8fe0563da811d1627034dd95ab3a8e10af

Author: Alex Henrie <alexhenrie24 at gmail.com>
Date:   Sat Jan 28 15:34:04 2017 -0700

ddraw: Don't crash if writing out a new ddraw2 surface segfaults.

Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ddraw/ddraw.c        | 20 ++++++++++++++------
 dlls/ddraw/tests/ddraw2.c |  2 ++
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index b8e2f57..1e69df4 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -2924,14 +2924,22 @@ static HRESULT WINAPI ddraw2_CreateSurface(IDirectDraw2 *iface,
 
     hr = ddraw_surface_create(ddraw, &surface_desc2, &impl, outer_unknown, 2);
     wined3d_mutex_unlock();
-    if (FAILED(hr))
+
+    __TRY
     {
-        *surface = NULL;
-        return hr;
+        if (FAILED(hr))
+        {
+            *surface = NULL;
+            break;
+        }
+        *surface = &impl->IDirectDrawSurface_iface;
+        impl->ifaceToRelease = NULL;
     }
-
-    *surface = &impl->IDirectDrawSurface_iface;
-    impl->ifaceToRelease = NULL;
+    __EXCEPT_PAGE_FAULT
+    {
+        hr = E_INVALIDARG;
+    }
+    __ENDTRY;
 
     return hr;
 }
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index ce3f6de..26c2c33 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -2119,6 +2119,8 @@ static void test_surface_qi(void)
     surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
     surface_desc.dwWidth = 512;
     surface_desc.dwHeight = 512;
+    hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface **)0xdeadbeef, NULL);
+    ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
     hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
     ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
 




More information about the wine-cvs mailing list