Skip to content

Commit

Permalink
Bug 1205456 - Check for UNKNOWN_APP_ID when serializing principals. r…
Browse files Browse the repository at this point in the history
…=sicking, a=sylvestre

--HG--
extra : source : 0e0f3104478fcb2ed29be54f3e5ee113245378b8
  • Loading branch information
bholley committed Sep 16, 2015
1 parent 12956aa commit b4e28e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions caps/nsNullPrincipal.cpp
Expand Up @@ -173,6 +173,9 @@ nsNullPrincipal::Read(nsIObjectInputStream* aStream)
NS_IMETHODIMP
nsNullPrincipal::Write(nsIObjectOutputStream* aStream)
{
NS_ENSURE_TRUE(mOriginAttributes.mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
NS_ERROR_INVALID_ARG);

nsAutoCString suffix;
OriginAttributesRef().CreateSuffix(suffix);

Expand Down
2 changes: 2 additions & 0 deletions caps/nsPrincipal.cpp
Expand Up @@ -446,6 +446,8 @@ NS_IMETHODIMP
nsPrincipal::Write(nsIObjectOutputStream* aStream)
{
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),
true);
Expand Down
14 changes: 14 additions & 0 deletions caps/tests/unit/test_origin.js
Expand Up @@ -103,6 +103,20 @@ function run_test() {
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 {
let binaryStream = Cc["@mozilla.org/binaryoutputstream;1"].
createInstance(Ci.nsIObjectOutputStream);
let pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
pipe.init(false, false, 0, 0xffffffff, null);
binaryStream.setOutputStream(pipe.outputStream);
binaryStream.writeCompoundObject(simplePrin, Ci.nsISupports, true);
binaryStream.close();
} catch (e) {
do_check_true(true);
}


// Just userContext.
var exampleOrg_userContext = ssm.createCodebasePrincipal(makeURI('http://example.org'), {userContextId: 42});
checkOriginAttributes(exampleOrg_userContext, { userContextId: 42 }, '^userContextId=42');
Expand Down

0 comments on commit b4e28e4

Please sign in to comment.