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

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


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

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

ddraw: Don't crash if writing out a new ddraw4 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 1850ac577038b8a16c4f153b9f3177e959f27c82)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

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

diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index c3dfdc5..1329587 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -2871,15 +2871,23 @@ static HRESULT WINAPI ddraw4_CreateSurface(IDirectDraw4 *iface,
 
     hr = ddraw_surface_create(ddraw, surface_desc, &impl, outer_unknown, 4);
     wined3d_mutex_unlock();
-    if (FAILED(hr))
+
+    __TRY
     {
-        *surface = NULL;
-        return hr;
+        if (FAILED(hr))
+        {
+            *surface = NULL;
+            break;
+        }
+        *surface = &impl->IDirectDrawSurface4_iface;
+        IDirectDraw4_AddRef(iface);
+        impl->ifaceToRelease = (IUnknown *)iface;
     }
-
-    *surface = &impl->IDirectDrawSurface4_iface;
-    IDirectDraw4_AddRef(iface);
-    impl->ifaceToRelease = (IUnknown *)iface;
+    __EXCEPT_PAGE_FAULT
+    {
+        hr = E_INVALIDARG;
+    }
+    __ENDTRY;
 
     return hr;
 }
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 40bfaaf..c51477c 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -2269,6 +2269,8 @@ static void test_surface_qi(void)
     surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
     surface_desc.dwWidth = 512;
     surface_desc.dwHeight = 512;
+    hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, (IDirectDrawSurface4 **)0xdeadbeef, NULL);
+    ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
     hr = IDirectDraw4_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