Bug 759783: Add identifying origin information to Javascript sandboxes. r=jlebar

This commit is contained in:
Nils Maier 2012-06-18 13:09:17 -04:00
parent 3f58a4b71f
commit 0c2db95ab0
2 changed files with 21 additions and 11 deletions

View File

@ -3542,9 +3542,13 @@ ParseOptionsObject(JSContext *cx, jsval from, SandboxOptions &options)
return NS_OK;
}
nsresult
GetSandboxNameFromStack(JSContext *cx, nsCString &sandboxName)
static nsresult
AssembleSandboxMemoryReporterName(JSContext *cx, nsCString &sandboxName)
{
// Use a default name when the caller did not provide a sandboxName.
if (sandboxName.IsEmpty())
sandboxName = NS_LITERAL_CSTRING("[anonymous sandbox]");
nsXPConnect* xpc = nsXPConnect::GetXPConnect();
NS_ENSURE_TRUE(xpc, NS_ERROR_XPC_UNEXPECTED);
@ -3557,8 +3561,19 @@ GetSandboxNameFromStack(JSContext *cx, nsCString &sandboxName)
nsCOMPtr<nsIStackFrame> frame;
xpc->GetCurrentJSStack(getter_AddRefs(frame));
if (frame)
frame->GetFilename(getter_Copies(sandboxName));
// Append the caller's location information.
if (frame) {
nsCString location;
PRInt32 lineNumber = 0;
frame->GetFilename(getter_Copies(location));
frame->GetLineNumber(&lineNumber);
sandboxName.AppendLiteral(" (from: ");
sandboxName.Append(location);
sandboxName.AppendLiteral(":");
sandboxName.AppendInt(lineNumber);
sandboxName.AppendLiteral(")");
}
return NS_OK;
}
@ -3602,13 +3617,8 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
if (argc > 1 && NS_FAILED(ParseOptionsObject(cx, argv[1], options)))
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
// If there is no options object given, or no sandboxName property
// specified, use the caller's filename as sandboxName.
if (options.sandboxName.IsEmpty() &&
NS_FAILED(GetSandboxNameFromStack(cx, options.sandboxName)))
{
if (NS_FAILED(AssembleSandboxMemoryReporterName(cx, options.sandboxName)))
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
}
rv = xpc_CreateSandboxObject(cx, vp, prinOrSop, options);

View File

@ -83,7 +83,7 @@
isXptiWorkingSetPresent = true;
} else if (aPath.search(/^explicit\/atom-table$/) >= 0) {
isAtomTablePresent = true;
} else if (aPath === "compartments\/system\/[System Principal], this-is-a-sandbox-name") {
} else if (/\[System Principal\].*this-is-a-sandbox-name/.test(aPath)) {
// A system compartment with a location (such as a sandbox) should
// show that location.
isSandboxLocationShown = true;