From fa14b0322376dcbf8260c3fbb47cd5ba74583ddf Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Thu, 30 Jan 2003 13:22:01 +0000 Subject: [PATCH] Fix ClassIsListed which returns wrong value when registry key is missing. b=191131 r=dbradley@netscape.com sr=darin@netscape.com a=asa@mozilla.org git-svn-id: svn://10.0.0.236/trunk@137142 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/xpconnect/src/nsDispatchSupport.cpp | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mozilla/js/src/xpconnect/src/nsDispatchSupport.cpp b/mozilla/js/src/xpconnect/src/nsDispatchSupport.cpp index da34efb7741..642a04b1213 100644 --- a/mozilla/js/src/xpconnect/src/nsDispatchSupport.cpp +++ b/mozilla/js/src/xpconnect/src/nsDispatchSupport.cpp @@ -45,17 +45,18 @@ #include "nsIActiveXSecurityPolicy.h" -static nsresult +static PRBool ClassIsListed(HKEY hkeyRoot, const TCHAR *szKey, const CLSID &clsid, PRBool &listIsEmpty) { // Test if the specified CLSID is found in the specified registry key - listIsEmpty = PR_FALSE; + listIsEmpty = PR_TRUE; CRegKey keyList; if(keyList.Open(hkeyRoot, szKey, KEY_READ) != ERROR_SUCCESS) { - return NS_ERROR_FAILURE; + // Class is not listed, because there is no key to read! + return PR_FALSE; } // Enumerate CLSIDs looking for this one @@ -68,20 +69,22 @@ ClassIsListed(HKEY hkeyRoot, const TCHAR *szKey, const CLSID &clsid, PRBool &lis { // An empty list if(i == 0) - listIsEmpty = PR_TRUE; - break; + break; } ++i; + listIsEmpty = PR_FALSE; szCLSID[kBufLength - 1] = TCHAR('\0'); CLSID clsidToCompare = GUID_NULL; if(SUCCEEDED(::CLSIDFromString(T2OLE(szCLSID), &clsidToCompare)) && ::IsEqualCLSID(clsid, clsidToCompare)) { - return NS_OK; + // Class is listed + return PR_TRUE; } } while (1); - return NS_ERROR_FAILURE; + // Class not found + return PR_FALSE; } static PRBool @@ -236,17 +239,17 @@ NS_IMETHODIMP nsDispatchSupport::IsClassSafeToHost(const nsCID & cid, PRBool *cl // Check if the CLSID belongs to a list that the Gecko does not support PRBool listIsEmpty = PR_FALSE; - if(NS_SUCCEEDED(ClassIsListed(HKEY_LOCAL_MACHINE, kControlsToDenyKey, clsid, listIsEmpty))) + if(ClassIsListed(HKEY_LOCAL_MACHINE, kControlsToDenyKey, clsid, listIsEmpty)) { *_retval = PR_FALSE; return NS_OK; } - // Check if the CLSID is in the whitelist. This test only cares when the whitelist is - // non-empty, to indicates that it is being used. + // Check if the CLSID is in the whitelist. This test only cares that the + // CLSID is not present when the whitelist is non-empty, to indicates that it is being used. listIsEmpty = PR_FALSE; - if(NS_FAILED(ClassIsListed(HKEY_LOCAL_MACHINE, kControlsToAllowKey, clsid, listIsEmpty)) && + if(!ClassIsListed(HKEY_LOCAL_MACHINE, kControlsToAllowKey, clsid, listIsEmpty) && !listIsEmpty) { *_retval = PR_FALSE;