Bug 1290350 - Make fallible some potentially large allocations in nsSimpleURI::GetSpec. r=valentin.

--HG--
extra : rebase_source : afb8e8a177eb171db1977ca8414eb01a6cd68838
This commit is contained in:
Nicholas Nethercote 2016-08-01 09:14:33 +10:00
parent 249cd65c71
commit 6fa37ab6c0

View File

@ -167,9 +167,17 @@ nsSimpleURI::Deserialize(const URIParams& aParams)
NS_IMETHODIMP
nsSimpleURI::GetSpec(nsACString &result)
{
result = mScheme + NS_LITERAL_CSTRING(":") + mPath;
if (!result.Assign(mScheme, fallible) ||
!result.Append(NS_LITERAL_CSTRING(":"), fallible) ||
!result.Append(mPath, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (mIsRefValid) {
result += NS_LITERAL_CSTRING("#") + mRef;
if (!result.Append(NS_LITERAL_CSTRING("#"), fallible) ||
!result.Append(mRef, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
} else {
MOZ_ASSERT(mRef.IsEmpty(), "mIsRefValid/mRef invariant broken");
}