From ba075c5d29dcc5e09888db86335c5f0e8b9fb4ce Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 24 Feb 2006 05:13:51 +0000 Subject: [PATCH] Followup fix for bug 307867 -- make sure to update our pointers to hashtable entries when the entries move. r=dveditz, sr=brendan, a=dveditz, branch181=dveditz git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_0_BRANCH@191140 18797224-902f-48f8-a5cc-f745e15eee43 --- .../caps/include/nsScriptSecurityManager.h | 32 ++++++++++++++++++- mozilla/caps/src/nsScriptSecurityManager.cpp | 8 ++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mozilla/caps/include/nsScriptSecurityManager.h b/mozilla/caps/include/nsScriptSecurityManager.h index 544970c7751..1d72ed54f42 100644 --- a/mozilla/caps/include/nsScriptSecurityManager.h +++ b/mozilla/caps/include/nsScriptSecurityManager.h @@ -65,6 +65,7 @@ class nsIXPConnect; class nsIStringBundle; class nsSystemPrincipal; struct ClassPolicy; +class DomainPolicy; #if defined(DEBUG_mstoltz) || defined(DEBUG_caillon) #define DEBUG_CAPS_HACKER @@ -208,6 +209,10 @@ struct ClassPolicy : public PLDHashEntryHdr { char* key; PLDHashTable* mPolicy; + + // Note: the DomainPolicy owns us, so if if dies we will too. Hence no + // need to refcount it here (and in fact, we'd probably leak if we tried). + DomainPolicy* mDomainWeAreWildcardFor; }; PR_STATIC_CALLBACK(void) @@ -222,6 +227,13 @@ ClearClassPolicyEntry(PLDHashTable *table, PLDHashEntryHdr *entry) PL_DHashTableDestroy(cp->mPolicy); } +// Note: actual impl is going to be after the DomainPolicy class definition, +// since we need to access members of DomainPolicy in the impl +PR_STATIC_CALLBACK(void) +MoveClassPolicyEntry(PLDHashTable *table, + const PLDHashEntryHdr *from, + PLDHashEntryHdr *to); + PR_STATIC_CALLBACK(PRBool) InitClassPolicyEntry(PLDHashTable *table, PLDHashEntryHdr *entry, @@ -241,6 +253,7 @@ InitClassPolicyEntry(PLDHashTable *table, }; ClassPolicy* cp = (ClassPolicy*)entry; + cp->mDomainWeAreWildcardFor = nsnull; cp->key = PL_strdup((const char*)key); if (!cp->key) return PR_FALSE; @@ -279,7 +292,7 @@ public: PL_DHashGetKeyStub, PL_DHashStringKey, PL_DHashMatchStringKey, - PL_DHashMoveEntryStub, + MoveClassPolicyEntry, ClearClassPolicyEntry, PL_DHashFinalizeStub, InitClassPolicyEntry @@ -336,6 +349,23 @@ private: }; +PR_STATIC_CALLBACK(void) +MoveClassPolicyEntry(PLDHashTable *table, + const PLDHashEntryHdr *from, + PLDHashEntryHdr *to) +{ + memcpy(to, from, table->entrySize); + + // Now update the mDefaultPolicy pointer that points to us, if any. + ClassPolicy* cp = NS_STATIC_CAST(ClassPolicy*, to); + if (cp->mDomainWeAreWildcardFor) { + NS_ASSERTION(cp->mDomainWeAreWildcardFor->mWildcardPolicy == + NS_STATIC_CAST(const ClassPolicy*, from), + "Unexpected wildcard policy on mDomainWeAreWildcardFor"); + cp->mDomainWeAreWildcardFor->mWildcardPolicy = cp; + } +} + ///////////////////////////// // nsScriptSecurityManager // ///////////////////////////// diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index aaf500b3f42..6d2fdabefe6 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -3311,9 +3311,15 @@ nsScriptSecurityManager::InitDomainPolicy(JSContext* cx, // If this is the wildcard class (class '*'), save it in mWildcardPolicy // (we leave it stored in the hashtable too to take care of the cleanup) - if ((*start == '*') && (end == start + 1)) + if ((*start == '*') && (end == start + 1)) { aDomainPolicy->mWildcardPolicy = cpolicy; + // Make sure that cpolicy knows about aDomainPolicy so it can reset + // the mWildcardPolicy pointer as needed if it gets moved in the + // hashtable. + cpolicy->mDomainWeAreWildcardFor = aDomainPolicy; + } + // Get the property name start = end + 1; end = PL_strchr(start, '.');