Backed out changeset d0e88c95f3c5 (bug 1167100) for crashes a=backout

This commit is contained in:
Wes Kocher 2015-09-29 10:25:20 -07:00
parent 5249c06cb0
commit 832bf936d8
9 changed files with 70 additions and 36 deletions

View File

@ -395,7 +395,7 @@ BasePrincipal::GetUnknownAppId(bool* aUnknownAppId)
}
already_AddRefed<BasePrincipal>
BasePrincipal::CreateCodebasePrincipal(nsIURI* aURI, const OriginAttributes& aAttrs)
BasePrincipal::CreateCodebasePrincipal(nsIURI* aURI, OriginAttributes& aAttrs)
{
// If the URI is supposed to inherit the security context of whoever loads it,
// we shouldn't make a codebase principal for it.

View File

@ -159,7 +159,7 @@ public:
virtual bool IsCodebasePrincipal() const { return false; };
static BasePrincipal* Cast(nsIPrincipal* aPrin) { return static_cast<BasePrincipal*>(aPrin); }
static already_AddRefed<BasePrincipal> CreateCodebasePrincipal(nsIURI* aURI, const OriginAttributes& aAttrs);
static already_AddRefed<BasePrincipal> CreateCodebasePrincipal(nsIURI* aURI, OriginAttributes& aAttrs);
const OriginAttributes& OriginAttributesRef() { return mOriginAttributes; }
uint32_t AppId() const { return mOriginAttributes.mAppId; }

View File

@ -425,14 +425,15 @@ StructuredCloneHelper::ReadFullySerializableObjects(JSContext* aCx,
} else if (aTag == SCTAG_DOM_NULL_PRINCIPAL) {
info = mozilla::ipc::NullPrincipalInfo();
} else {
uint32_t suffixLength, specLength;
if (!JS_ReadUint32Pair(aReader, &suffixLength, &specLength)) {
uint32_t appId = aIndex;
uint32_t isInBrowserElement, specLength;
if (!JS_ReadUint32Pair(aReader, &isInBrowserElement, &specLength)) {
return nullptr;
}
nsAutoCString suffix;
suffix.SetLength(suffixLength);
if (!JS_ReadBytes(aReader, suffix.BeginWriting(), suffixLength)) {
uint32_t signedPkgLength, dummy;
if (!JS_ReadUint32Pair(aReader, &signedPkgLength, &dummy)) {
return nullptr;
}
@ -442,9 +443,14 @@ StructuredCloneHelper::ReadFullySerializableObjects(JSContext* aCx,
return nullptr;
}
OriginAttributes attrs;
attrs.PopulateFromSuffix(suffix);
info = mozilla::ipc::ContentPrincipalInfo(attrs, spec);
nsAutoCString signedPkg;
signedPkg.SetLength(signedPkgLength);
if (!JS_ReadBytes(aReader, signedPkg.BeginWriting(), signedPkgLength)) {
return nullptr;
}
info = mozilla::ipc::ContentPrincipalInfo(appId, isInBrowserElement,
spec, signedPkg);
}
nsresult rv;
@ -571,12 +577,13 @@ StructuredCloneHelper::WriteFullySerializableObjects(JSContext* aCx,
MOZ_ASSERT(info.type() == mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
const mozilla::ipc::ContentPrincipalInfo& cInfo = info;
nsAutoCString suffix;
cInfo.attrs().CreateSuffix(suffix);
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_CONTENT_PRINCIPAL, 0) &&
JS_WriteUint32Pair(aWriter, suffix.Length(), cInfo.spec().Length()) &&
JS_WriteBytes(aWriter, suffix.get(), suffix.Length()) &&
JS_WriteBytes(aWriter, cInfo.spec().get(), cInfo.spec().Length());
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_CONTENT_PRINCIPAL,
cInfo.appId()) &&
JS_WriteUint32Pair(aWriter, cInfo.isInBrowserElement(),
cInfo.spec().Length()) &&
JS_WriteUint32Pair(aWriter, cInfo.signedPkg().Length(), 0) &&
JS_WriteBytes(aWriter, cInfo.spec().get(), cInfo.spec().Length()) &&
JS_WriteBytes(aWriter, cInfo.signedPkg().get(), cInfo.signedPkg().Length());
}
}

View File

@ -81,7 +81,7 @@ IsTrusted(const PrincipalInfo& aPrincipalInfo, bool aTestingPrefEnabled)
// worker. We require exact knowledge of this information before allowing
// the caller to touch the disk using the Cache API.
if (NS_WARN_IF(aPrincipalInfo.type() != PrincipalInfo::TContentPrincipalInfo ||
aPrincipalInfo.get_ContentPrincipalInfo().attrs().mAppId ==
aPrincipalInfo.get_ContentPrincipalInfo().appId() ==
nsIScriptSecurityManager::UNKNOWN_APP_ID)) {
return false;
}

View File

@ -1740,8 +1740,10 @@ InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
serializedInfo.Append(cInfo.spec());
MOZ_ASSERT(cInfo.appId() != nsIScriptSecurityManager::UNKNOWN_APP_ID);
OriginAttributes attrs(cInfo.appId(), cInfo.isInBrowserElement());
nsAutoCString suffix;
cInfo.attrs().CreateSuffix(suffix);
attrs.CreateSuffix(suffix);
serializedInfo.Append(suffix);
}
@ -1911,8 +1913,9 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
return NS_ERROR_FAILURE;
}
nsCString signedPkg = NS_ConvertUTF16toUTF8(attrs.mSignedPkg);
aSavedResponseOut->mValue.principalInfo() =
mozilla::ipc::ContentPrincipalInfo(attrs, originNoSuffix);
mozilla::ipc::ContentPrincipalInfo(attrs.mAppId, attrs.mInBrowser, originNoSuffix, signedPkg);
}
int32_t redirected;

View File

@ -332,8 +332,9 @@ ServiceWorkerRegistrar::ReadData()
}
GET_LINE(line);
nsCString signedPkg = NS_ConvertUTF16toUTF8(attrs.mSignedPkg);
entry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, line);
mozilla::ipc::ContentPrincipalInfo(attrs.mAppId, attrs.mInBrowser, line, signedPkg);
GET_LINE(entry->scope());
GET_LINE(entry->scriptSpec());
@ -548,8 +549,9 @@ ServiceWorkerRegistrar::WriteData()
const mozilla::ipc::ContentPrincipalInfo& cInfo =
info.get_ContentPrincipalInfo();
OriginAttributes attrs(cInfo.appId(), cInfo.isInBrowserElement());
nsAutoCString suffix;
cInfo.attrs().CreateSuffix(suffix);
attrs.CreateSuffix(suffix);
buffer.Truncate();
buffer.Append(suffix.get());

View File

@ -163,8 +163,9 @@ TEST(ServiceWorkerRegistrar, TestReadData)
ASSERT_EQ(info0.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
const mozilla::ipc::ContentPrincipalInfo& cInfo0 = data[0].principal();
mozilla::OriginAttributes attrs0(cInfo0.appId(), cInfo0.isInBrowserElement());
nsAutoCString suffix0;
cInfo0.attrs().CreateSuffix(suffix0);
attrs0.CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("spec 0", cInfo0.spec().get());
@ -178,8 +179,9 @@ TEST(ServiceWorkerRegistrar, TestReadData)
ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
const mozilla::ipc::ContentPrincipalInfo& cInfo1 = data[1].principal();
mozilla::OriginAttributes attrs1(cInfo1.appId(), cInfo1.isInBrowserElement());
nsAutoCString suffix1;
cInfo1.attrs().CreateSuffix(suffix1);
attrs1.CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("spec 1", cInfo1.spec().get());
@ -219,7 +221,7 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
nsAutoCString spec;
spec.AppendPrintf("spec write %d", i);
d->principal() = mozilla::ipc::ContentPrincipalInfo(mozilla::OriginAttributes(i, i % 2), spec);
d->principal() = mozilla::ipc::ContentPrincipalInfo(i, i % 2, spec, EmptyCString());
d->scope().AppendPrintf("scope write %d", i);
d->scriptSpec().AppendPrintf("scriptSpec write %d", i);
d->currentWorkerURL().AppendPrintf("currentWorkerURL write %d", i);
@ -245,12 +247,8 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
ASSERT_EQ(data[i].principal().type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
const mozilla::ipc::ContentPrincipalInfo& cInfo = data[i].principal();
mozilla::OriginAttributes attrs(i, i % 2);
nsAutoCString suffix, expectSuffix;
attrs.CreateSuffix(expectSuffix);
cInfo.attrs().CreateSuffix(suffix);
ASSERT_STREQ(expectSuffix.get(), suffix.get());
ASSERT_EQ((uint32_t)i, cInfo.appId());
ASSERT_EQ((uint32_t)(i % 2), (uint32_t)cInfo.isInBrowserElement());
test.AppendPrintf("spec write %d", i);
ASSERT_STREQ(test.get(), cInfo.spec().get());

View File

@ -25,6 +25,7 @@ class OptionalLoadInfoArgs;
}
using mozilla::BasePrincipal;
using mozilla::OriginAttributes;
using namespace mozilla::net;
namespace ipc {
@ -76,10 +77,13 @@ PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
return nullptr;
}
if (info.attrs().mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
if (info.appId() == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
rv = secMan->GetSimpleCodebasePrincipal(uri, getter_AddRefs(principal));
} else {
principal = BasePrincipal::CreateCodebasePrincipal(uri, info.attrs());
// TODO: Bug 1167100 - User nsIPrincipal.originAttribute in ContentPrincipalInfo
OriginAttributes attrs(info.appId(), info.isInBrowserElement());
attrs.mSignedPkg = NS_ConvertUTF8toUTF16(info.signedPkg());
principal = BasePrincipal::CreateCodebasePrincipal(uri, attrs);
rv = principal ? NS_OK : NS_ERROR_FAILURE;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -199,14 +203,33 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
return rv;
}
const mozilla::OriginAttributes& attr =
mozilla::BasePrincipal::Cast(aPrincipal)->OriginAttributesRef();
nsCString signedPkg = NS_ConvertUTF16toUTF8(attr.mSignedPkg);
bool isUnknownAppId;
rv = aPrincipal->GetUnknownAppId(&isUnknownAppId);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
*aPrincipalInfo = ContentPrincipalInfo(BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(),
spec);
uint32_t appId;
if (isUnknownAppId) {
appId = nsIScriptSecurityManager::UNKNOWN_APP_ID;
} else {
rv = aPrincipal->GetAppId(&appId);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
bool isInBrowserElement;
rv = aPrincipal->GetIsInBrowserElement(&isInBrowserElement);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
*aPrincipalInfo = ContentPrincipalInfo(appId, isInBrowserElement, spec, signedPkg);
return NS_OK;
}

View File

@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
namespace mozilla {
@ -10,8 +9,10 @@ namespace ipc {
struct ContentPrincipalInfo
{
OriginAttributes attrs;
uint32_t appId;
bool isInBrowserElement;
nsCString spec;
nsCString signedPkg;
};
struct SystemPrincipalInfo