From a26bfabac3940176f412896241ffab5c7f92baaa Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Tue, 2 Feb 2016 12:53:47 +0800
Subject: ole32: Add a check for hglobal pointer to GetHGlobalFromStream.

---
 dlls/ole32/hglobalstream.c       | 4 ++--
 dlls/ole32/tests/hglobalstream.c | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/dlls/ole32/hglobalstream.c b/dlls/ole32/hglobalstream.c
index 655e380..b86de56 100644
--- a/dlls/ole32/hglobalstream.c
+++ b/dlls/ole32/hglobalstream.c
@@ -621,10 +621,10 @@ HRESULT WINAPI GetHGlobalFromStream(IStream* pstm, HGLOBAL* phglobal)
 {
   HGLOBALStreamImpl* pStream;
 
-  if (pstm == NULL)
+  if (!pstm || !phglobal)
     return E_INVALIDARG;
 
-  pStream = (HGLOBALStreamImpl*) pstm;
+  pStream = impl_from_IStream(pstm);
 
   /*
    * Verify that the stream object was created with CreateStreamOnHGlobal.
diff --git a/dlls/ole32/tests/hglobalstream.c b/dlls/ole32/tests/hglobalstream.c
index 0dc3c52..0453e54 100644
--- a/dlls/ole32/tests/hglobalstream.c
+++ b/dlls/ole32/tests/hglobalstream.c
@@ -555,6 +555,12 @@ static void test_IStream_Clone(void)
     hr = CreateStreamOnHGlobal(orig_hmem, TRUE, &stream);
     ok(hr == S_OK, "unexpected %#x\n", hr);
 
+    hr = GetHGlobalFromStream(stream, NULL);
+    ok(hr == E_INVALIDARG, "unexpected %#x\n", hr);
+
+    hr = GetHGlobalFromStream(NULL, &hmem);
+    ok(hr == E_INVALIDARG, "unexpected %#x\n", hr);
+
     stream_info(stream, &hmem, &size, &pos);
     ok(hmem == orig_hmem, "handles should match\n");
     ok(size == 0,  "unexpected %d\n", size);
-- 
2.7.0

