>From 291a6e59ecac75da918886487ab65724bcb32129 Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Mon, 23 Jan 2012 12:21:23 +1100
Subject: [PATCH] ActiveX objects might not support IServiceProvider Interface
To: wine-patches <wine-patches@winehq.org>

---
 dlls/jscript/activex.c       |    1 +
 dlls/jscript/jscript.c       |   13 ++++++++++---
 dlls/jscript/tests/activex.c |   30 +++++++++++++++++++++++++++++-
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/dlls/jscript/activex.c b/dlls/jscript/activex.c
index 41e2065..7fff847 100644
--- a/dlls/jscript/activex.c
+++ b/dlls/jscript/activex.c
@@ -129,6 +129,7 @@ static IUnknown *create_activex_object(script_ctx_t *ctx, const WCHAR *progid)
             IUnknown_Release(ax_site);
         }
         IObjectWithSite_Release(obj_site);
+
         if(!ax_site || FAILED(hres)) {
             IUnknown_Release(obj);
             return NULL;
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index be225b7..68ace36 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -287,7 +287,12 @@ static ULONG WINAPI AXSite_Release(IServiceProvider *iface)
     TRACE("(%p) ref=%d\n", This, ref);
 
     if(!ref)
+    {
+        if(This->sp)
+            IServiceProvider_Release(This->sp);
+
         heap_free(This);
+    }
 
     return ref;
 }
@@ -299,6 +304,9 @@ static HRESULT WINAPI AXSite_QueryService(IServiceProvider *iface,
 
     TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
 
+    if(!This->sp)
+        return E_NOINTERFACE;
+
     return IServiceProvider_QueryService(This->sp, guidService, riid, ppv);
 }
 
@@ -311,14 +319,13 @@ static IServiceProviderVtbl AXSiteVtbl = {
 
 IUnknown *create_ax_site(script_ctx_t *ctx)
 {
-    IServiceProvider *sp;
+    IServiceProvider *sp = NULL;
     AXSite *ret;
     HRESULT hres;
 
     hres = IActiveScriptSite_QueryInterface(ctx->site, &IID_IServiceProvider, (void**)&sp);
     if(FAILED(hres)) {
-        ERR("Could not get IServiceProvider iface: %08x\n", hres);
-        return NULL;
+        TRACE("Could not get IServiceProvider iface: %08x\n", hres);
     }
 
     ret = heap_alloc(sizeof(AXSite));
diff --git a/dlls/jscript/tests/activex.c b/dlls/jscript/tests/activex.c
index 4e0fcf5..99d3aa2 100644
--- a/dlls/jscript/tests/activex.c
+++ b/dlls/jscript/tests/activex.c
@@ -80,6 +80,7 @@ static DWORD QueryCustomPolicy_psize;
 static DWORD QueryCustomPolicy_policy;
 static HRESULT QI_IDispatch_hres;
 static HRESULT SetSite_hres;
+static BOOL AllowIServiceProvider;
 
 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
 
@@ -148,6 +149,7 @@ static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *p
 
 
     CHECK_EXPECT(SetSite);
+
     ok(pUnkSite != NULL, "pUnkSite == NULL\n");
 
     hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
@@ -575,7 +577,7 @@ static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface,
         *ppv = iface;
     }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
         *ppv = iface;
-    }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
+    }else if(IsEqualGUID(&IID_IServiceProvider, riid) && AllowIServiceProvider) {
         *ppv = &ServiceProvider;
     }else {
         *ppv = NULL;
@@ -718,6 +720,7 @@ static IActiveScriptParse *create_script(BOOL skip_tests, BOOL use_sec_mgr)
     QueryCustomPolicy_policy = URLPOLICY_ALLOW;
     QI_IDispatch_hres = S_OK;
     SetSite_hres = S_OK;
+    AllowIServiceProvider = TRUE;
 
     hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
             &IID_IActiveScript, (void**)&script);
@@ -1032,6 +1035,31 @@ static void test_ActiveXObject(void)
     CHECK_CALLED(SetSite);
 
     IUnknown_Release(parser);
+
+    /* No IServiceProvider Interface */
+    parser = create_script(FALSE, FALSE);
+    object_with_site = &ObjectWithSite;
+    AllowIServiceProvider = FALSE;
+
+    SET_EXPECT(CreateInstance);
+    SET_EXPECT(QI_IObjectWithSite);
+    SET_EXPECT(reportSuccess);
+    SET_EXPECT(SetSite);
+    parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
+    CHECK_CALLED(CreateInstance);
+    CHECK_CALLED(QI_IObjectWithSite);
+    CHECK_CALLED(reportSuccess);
+    CHECK_CALLED(SetSite);
+
+    IUnknown_Release(parser);
+
+    parser = create_script(FALSE, TRUE);
+    object_with_site = &ObjectWithSite;
+    AllowIServiceProvider = FALSE;
+
+    parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
+
+    IUnknown_Release(parser);
 }
 
 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
-- 
1.7.5.4

