зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1297300 - Add missing checks to GetSpec() calls in caps/ and js/. r=mrbkap.
This required making GetScriptLocation() fallible. --HG-- extra : rebase_source : a678e86c443988897d88550bec1cd1d21c3e919e
This commit is contained in:
Родитель
37301e25ad
Коммит
8c9e80a613
|
@ -88,8 +88,9 @@ JSPrincipals::dump()
|
|||
{
|
||||
if (debugToken == nsJSPrincipals::DEBUG_TOKEN) {
|
||||
nsAutoCString str;
|
||||
static_cast<nsJSPrincipals *>(this)->GetScriptLocation(str);
|
||||
fprintf(stderr, "nsIPrincipal (%p) = %s\n", static_cast<void*>(this), str.get());
|
||||
nsresult rv = static_cast<nsJSPrincipals *>(this)->GetScriptLocation(str);
|
||||
fprintf(stderr, "nsIPrincipal (%p) = %s\n", static_cast<void*>(this),
|
||||
NS_SUCCEEDED(rv) ? str.get() : "(unknown)");
|
||||
} else if (debugToken == dom::workers::kJSPrincipalsDebugToken) {
|
||||
fprintf(stderr, "Web Worker principal singleton (%p)\n", this);
|
||||
} else {
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
/**
|
||||
* Return a string that can be used as JS script filename in error reports.
|
||||
*/
|
||||
virtual void GetScriptLocation(nsACString &aStr) = 0;
|
||||
virtual nsresult GetScriptLocation(nsACString &aStr) = 0;
|
||||
static const uint32_t DEBUG_TOKEN = 0x0bf41760;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -78,10 +78,10 @@ nsNullPrincipal::Init(const PrincipalOriginAttributes& aOriginAttributes)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsresult
|
||||
nsNullPrincipal::GetScriptLocation(nsACString &aStr)
|
||||
{
|
||||
mURI->GetSpec(aStr);
|
||||
return mURI->GetSpec(aStr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
nsresult Init(const mozilla::PrincipalOriginAttributes& aOriginAttributes = mozilla::PrincipalOriginAttributes());
|
||||
|
||||
virtual void GetScriptLocation(nsACString &aStr) override;
|
||||
virtual nsresult GetScriptLocation(nsACString &aStr) override;
|
||||
|
||||
PrincipalKind Kind() override { return eNullPrincipal; }
|
||||
|
||||
|
|
|
@ -96,7 +96,8 @@ NS_IMETHODIMP
|
|||
nsNullPrincipalURI::GetAsciiSpec(nsACString &_spec)
|
||||
{
|
||||
nsAutoCString buffer;
|
||||
(void)GetSpec(buffer);
|
||||
// Ignore the return value -- nsNullPrincipalURI::GetSpec() is infallible.
|
||||
Unused << GetSpec(buffer);
|
||||
NS_EscapeURL(buffer, esc_OnlyNonASCII | esc_AlwaysCopy, _spec);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -99,10 +99,10 @@ nsPrincipal::Init(nsIURI *aCodebase, const PrincipalOriginAttributes& aOriginAtt
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsresult
|
||||
nsPrincipal::GetScriptLocation(nsACString &aStr)
|
||||
{
|
||||
mCodebase->GetSpec(aStr);
|
||||
return mCodebase->GetSpec(aStr);
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
|
@ -806,7 +806,7 @@ nsExpandedPrincipal::IsOnCSSUnprefixingWhitelist()
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
nsresult
|
||||
nsExpandedPrincipal::GetScriptLocation(nsACString& aStr)
|
||||
{
|
||||
aStr.Assign("[Expanded Principal [");
|
||||
|
@ -816,12 +816,14 @@ nsExpandedPrincipal::GetScriptLocation(nsACString& aStr)
|
|||
}
|
||||
|
||||
nsAutoCString spec;
|
||||
nsJSPrincipals::get(mPrincipals.ElementAt(i))->GetScriptLocation(spec);
|
||||
nsresult rv =
|
||||
nsJSPrincipals::get(mPrincipals.ElementAt(i))->GetScriptLocation(spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aStr.Append(spec);
|
||||
|
||||
}
|
||||
aStr.Append("]]");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
// Init() must be called before the principal is in a usable state.
|
||||
nsresult Init(nsIURI* aCodebase, const mozilla::PrincipalOriginAttributes& aOriginAttributes);
|
||||
|
||||
virtual void GetScriptLocation(nsACString& aStr) override;
|
||||
virtual nsresult GetScriptLocation(nsACString& aStr) override;
|
||||
void SetURI(nsIURI* aURI);
|
||||
|
||||
/**
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
||||
virtual bool AddonHasPermission(const nsAString& aPerm) override;
|
||||
virtual bool IsOnCSSUnprefixingWhitelist() override;
|
||||
virtual void GetScriptLocation(nsACString &aStr) override;
|
||||
virtual nsresult GetScriptLocation(nsACString &aStr) override;
|
||||
nsresult GetOriginInternal(nsACString& aOrigin) override;
|
||||
|
||||
PrincipalKind Kind() override { return eExpandedPrincipal; }
|
||||
|
|
|
@ -31,10 +31,11 @@ NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrincipal,
|
|||
|
||||
#define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
|
||||
|
||||
void
|
||||
nsresult
|
||||
nsSystemPrincipal::GetScriptLocation(nsACString &aStr)
|
||||
{
|
||||
aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
nsSystemPrincipal() {}
|
||||
|
||||
virtual void GetScriptLocation(nsACString &aStr) override;
|
||||
virtual nsresult GetScriptLocation(nsACString &aStr) override;
|
||||
|
||||
protected:
|
||||
virtual ~nsSystemPrincipal(void) {}
|
||||
|
|
|
@ -367,14 +367,14 @@ AsyncScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
|||
RootedFunction function(cx);
|
||||
RootedScript script(cx);
|
||||
nsAutoCString spec;
|
||||
uri->GetSpec(spec);
|
||||
nsresult rv = uri->GetSpec(spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
RootedObject target_obj(cx, mTargetObj);
|
||||
|
||||
nsresult rv = PrepareScript(uri, cx, target_obj, spec.get(),
|
||||
mCharset,
|
||||
reinterpret_cast<const char*>(aBuf), aLength,
|
||||
mReuseGlobal, &script, &function);
|
||||
rv = PrepareScript(uri, cx, target_obj, spec.get(), mCharset,
|
||||
reinterpret_cast<const char*>(aBuf), aLength,
|
||||
mReuseGlobal, &script, &function);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -1764,7 +1764,8 @@ xpc::EvalInSandbox(JSContext* cx, HandleObject sandboxArg, const nsAString& sour
|
|||
filenameBuf.Assign(filename);
|
||||
} else {
|
||||
// Default to the spec of the principal.
|
||||
nsJSPrincipals::get(prin)->GetScriptLocation(filenameBuf);
|
||||
nsresult rv = nsJSPrincipals::get(prin)->GetScriptLocation(filenameBuf);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
lineNo = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1668,7 +1668,10 @@ GetCompartmentName(JSCompartment* c, nsCString& name, int* anonymizeID,
|
|||
name.AppendPrintf("<anonymized-%d>", *anonymizeID);
|
||||
*anonymizeID += 1;
|
||||
} else if (JSPrincipals* principals = JS_GetCompartmentPrincipals(c)) {
|
||||
nsJSPrincipals::get(principals)->GetScriptLocation(name);
|
||||
nsresult rv = nsJSPrincipals::get(principals)->GetScriptLocation(name);
|
||||
if (NS_FAILED(rv)) {
|
||||
name.AssignLiteral("(unknown)");
|
||||
}
|
||||
|
||||
// If the compartment's location (name) differs from the principal's
|
||||
// script location, append the compartment's location to allow
|
||||
|
|
Загрузка…
Ссылка в новой задаче