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

Alexandre Julliard julliard at winehq.org
Thu Jul 20 12:11:30 CDT 2017


Module: wine
Branch: stable
Commit: 8f2fec9af9dec770eb24eb71094c35b06d1caed9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8f2fec9af9dec770eb24eb71094c35b06d1caed9

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

ddraw: Don't crash if writing out a new ddraw7 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>
(cherry picked from commit c9e29bff7bbded119e9052b6740545e70cafdcd8)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/ddraw/ddraw.c        | 22 +++++++++++++++-------
 dlls/ddraw/tests/ddraw7.c |  2 ++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index 1329587..10bba4e 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -2817,15 +2817,23 @@ static HRESULT WINAPI ddraw7_CreateSurface(IDirectDraw7 *iface, DDSURFACEDESC2 *
 
     hr = ddraw_surface_create(ddraw, surface_desc, &impl, outer_unknown, 7);
     wined3d_mutex_unlock();
-    if (FAILED(hr))
+
+    __TRY
     {
-        *surface = NULL;
-        return hr;
+        if (FAILED(hr))
+        {
+            *surface = NULL;
+            break;
+        }
+        *surface = &impl->IDirectDrawSurface7_iface;
+        IDirectDraw7_AddRef(iface);
+        impl->ifaceToRelease = (IUnknown *)iface;
     }
-
-    *surface = &impl->IDirectDrawSurface7_iface;
-    IDirectDraw7_AddRef(iface);
-    impl->ifaceToRelease = (IUnknown *)iface;
+    __EXCEPT_PAGE_FAULT
+    {
+        hr = E_INVALIDARG;
+    }
+    __ENDTRY;
 
     return hr;
 }
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 1dd7cb1..9fa2593 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -1996,6 +1996,8 @@ static void test_surface_qi(void)
     surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
     surface_desc.dwWidth = 512;
     surface_desc.dwHeight = 512;
+    hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface7 **)0xdeadbeef, NULL);
+    ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
     hr = IDirectDraw7_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