Bug 1209843 - Stop checking for UNKNOWN_APP_ID in all places except those where AppId() is explicitly queried. r=sicking

This commit is contained in:
Bobby Holley 2015-09-29 19:42:21 -07:00
Родитель 8869fe8278
Коммит ca4a8095de
4 изменённых файлов: 1 добавлений и 28 удалений

Просмотреть файл

@ -53,8 +53,6 @@ bool OriginAttributes::CopyFromLoadContext(nsILoadContext* aLoadContext)
void void
OriginAttributes::CreateSuffix(nsACString& aStr) const OriginAttributes::CreateSuffix(nsACString& aStr) const
{ {
MOZ_RELEASE_ASSERT(mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
UniquePtr<URLParams> params(new URLParams()); UniquePtr<URLParams> params(new URLParams());
nsAutoString value; nsAutoString value;
@ -127,10 +125,6 @@ public:
return false; return false;
} }
if (mOriginAttributes->mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
return false;
}
return true; return true;
} }
@ -222,14 +216,6 @@ BasePrincipal::GetOrigin(nsACString& aOrigin)
nsresult rv = GetOriginInternal(aOrigin); nsresult rv = GetOriginInternal(aOrigin);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// OriginAttributes::CreateSuffix asserts against UNKNOWN_APP_ID. It's trivial
// to trigger this getter from script on such a principal, so we handle it
// here at the API entry point.
if (mOriginAttributes.mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
NS_WARNING("Refusing to provide canonical origin string to principal with UNKNOWN_APP_ID");
return NS_ERROR_FAILURE;
}
nsAutoCString suffix; nsAutoCString suffix;
mOriginAttributes.CreateSuffix(suffix); mOriginAttributes.CreateSuffix(suffix);
aOrigin.Append(suffix); aOrigin.Append(suffix);
@ -325,8 +311,6 @@ BasePrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
NS_IMETHODIMP NS_IMETHODIMP
BasePrincipal::GetJarPrefix(nsACString& aJarPrefix) BasePrincipal::GetJarPrefix(nsACString& aJarPrefix)
{ {
MOZ_ASSERT(AppId() != nsIScriptSecurityManager::UNKNOWN_APP_ID);
mozilla::GetJarPrefix(mOriginAttributes.mAppId, mOriginAttributes.mInBrowser, aJarPrefix); mozilla::GetJarPrefix(mOriginAttributes.mAppId, mOriginAttributes.mInBrowser, aJarPrefix);
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -57,7 +57,6 @@ nsresult
nsNullPrincipal::Init(const OriginAttributes& aOriginAttributes) nsNullPrincipal::Init(const OriginAttributes& aOriginAttributes)
{ {
mOriginAttributes = aOriginAttributes; mOriginAttributes = aOriginAttributes;
MOZ_ASSERT(AppId() != nsIScriptSecurityManager::UNKNOWN_APP_ID);
mURI = nsNullPrincipalURI::Create(); mURI = nsNullPrincipalURI::Create();
NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_AVAILABLE); NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_AVAILABLE);
@ -173,9 +172,6 @@ nsNullPrincipal::Read(nsIObjectInputStream* aStream)
NS_IMETHODIMP NS_IMETHODIMP
nsNullPrincipal::Write(nsIObjectOutputStream* aStream) nsNullPrincipal::Write(nsIObjectOutputStream* aStream)
{ {
NS_ENSURE_TRUE(mOriginAttributes.mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
NS_ERROR_INVALID_ARG);
nsAutoCString suffix; nsAutoCString suffix;
OriginAttributesRef().CreateSuffix(suffix); OriginAttributesRef().CreateSuffix(suffix);

Просмотреть файл

@ -427,9 +427,6 @@ NS_IMETHODIMP
nsPrincipal::Write(nsIObjectOutputStream* aStream) nsPrincipal::Write(nsIObjectOutputStream* aStream)
{ {
NS_ENSURE_STATE(mCodebase); NS_ENSURE_STATE(mCodebase);
NS_ENSURE_TRUE(mOriginAttributes.mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
NS_ERROR_INVALID_ARG);
nsresult rv = NS_WriteOptionalCompoundObject(aStream, mCodebase, NS_GET_IID(nsIURI), nsresult rv = NS_WriteOptionalCompoundObject(aStream, mCodebase, NS_GET_IID(nsIURI),
true); true);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {

Просмотреть файл

@ -98,11 +98,7 @@ function run_test() {
checkOriginAttributes(exampleOrg_addon, { addonId: "dummy" }, '^addonId=dummy'); checkOriginAttributes(exampleOrg_addon, { addonId: "dummy" }, '^addonId=dummy');
do_check_eq(exampleOrg_addon.origin, 'http://example.org^addonId=dummy'); do_check_eq(exampleOrg_addon.origin, 'http://example.org^addonId=dummy');
// Make sure that we refuse to create .origin for principals with UNKNOWN_APP_ID. // Make sure we don't crash when serializing principals with UNKNOWN_APP_ID.
var simplePrin = ssm.getSimpleCodebasePrincipal(makeURI('http://example.com'));
try { simplePrin.origin; do_check_true(false); } catch (e) { do_check_true(true); }
// Make sure we don't crash when serializing them either.
try { try {
let binaryStream = Cc["@mozilla.org/binaryoutputstream;1"]. let binaryStream = Cc["@mozilla.org/binaryoutputstream;1"].
createInstance(Ci.nsIObjectOutputStream); createInstance(Ci.nsIObjectOutputStream);