| File: | root/firefox-clang/obj-x86_64-pc-linux-gnu/caps/./../../caps/ExpandedPrincipal.cpp |
| Warning: | line 207, column 12 Value stored to 'rv' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | #include "ExpandedPrincipal.h" |
| 6 | |
| 7 | #include "ExpandedPrincipalJSONHandler.h" |
| 8 | #include "SubsumedPrincipalJSONHandler.h" |
| 9 | #include "js/JSON.h" |
| 10 | #include "mozilla/Base64.h" |
| 11 | #include "mozilla/JSONWriter.h" |
| 12 | #include "mozilla/extensions/WebExtensionPolicy.h" |
| 13 | #include "nsCharSeparatedTokenizer.h" |
| 14 | #include "nsIClassInfoImpl.h" |
| 15 | #include "nsIObjectInputStream.h" |
| 16 | #include "nsReadableUtils.h" |
| 17 | |
| 18 | using namespace mozilla; |
| 19 | |
| 20 | NS_IMPL_CLASSINFO(ExpandedPrincipal, nullptr, 0, NS_EXPANDEDPRINCIPAL_CID)extern nsresult ExpandedPrincipal_GetInterfacesHelper(nsTArray <nsIID> & array); static const GenericClassInfo::ClassInfoData kExpandedPrincipalClassInfoData = { ExpandedPrincipal_GetInterfacesHelper , nullptr, 0 | nsIClassInfo::SINGLETON_CLASSINFO, {0xe8ee88b0 , 0x5571, 0x4086, {0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb }}, }; mozilla::AlignedStorage2<GenericClassInfo> kExpandedPrincipalClassInfoDataPlace ; nsIClassInfo* gExpandedPrincipal_classInfoGlobal = nullptr; |
| 21 | NS_IMPL_QUERY_INTERFACE_CI(ExpandedPrincipal, nsIPrincipal,static_assert(2 > 0, "Need more arguments to NS_IMPL_QUERY_INTERFACE_CI" ); nsresult ExpandedPrincipal::QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "./../../caps/ExpandedPrincipal.cpp", 22); MOZ_PretendNoReturn (); } } while (0); nsISupports* foundInterface; if (aIID.Equals (mozilla::detail::kImplementedIID<std::remove_reference_t< decltype(*this)>, nsIPrincipal>)) foundInterface = static_cast <nsIPrincipal*>(this); else if (aIID.Equals(mozilla::detail ::kImplementedIID<std::remove_reference_t<decltype(*this )>, nsIExpandedPrincipal>)) foundInterface = static_cast <nsIExpandedPrincipal*>(this); else if (aIID.Equals(mozilla ::detail::kImplementedIID<std::remove_reference_t<decltype (*this)>, nsISupports>)) foundInterface = static_cast< nsISupports*>(static_cast<nsIPrincipal*>(this)); else if (aIID.Equals((nsIClassInfo::kIID))) { if (!gExpandedPrincipal_classInfoGlobal ) gExpandedPrincipal_classInfoGlobal = new (kExpandedPrincipalClassInfoDataPlace .addr()) GenericClassInfo(&kExpandedPrincipalClassInfoData ); foundInterface = gExpandedPrincipal_classInfoGlobal; } else foundInterface = 0; nsresult status; if (!foundInterface) { do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aIID.Equals((nsISupports::kIID)))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aIID.Equals((nsISupports::kIID ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!aIID.Equals((nsISupports::kIID))", "./../../caps/ExpandedPrincipal.cpp" , 22); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::kIID))" ")"); do { MOZ_CrashSequence(__null, 22); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE ; } else { (foundInterface)->AddRef(); status = NS_OK; } * aInstancePtr = foundInterface; return status; } |
| 22 | nsIExpandedPrincipal)static_assert(2 > 0, "Need more arguments to NS_IMPL_QUERY_INTERFACE_CI" ); nsresult ExpandedPrincipal::QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "./../../caps/ExpandedPrincipal.cpp", 22); MOZ_PretendNoReturn (); } } while (0); nsISupports* foundInterface; if (aIID.Equals (mozilla::detail::kImplementedIID<std::remove_reference_t< decltype(*this)>, nsIPrincipal>)) foundInterface = static_cast <nsIPrincipal*>(this); else if (aIID.Equals(mozilla::detail ::kImplementedIID<std::remove_reference_t<decltype(*this )>, nsIExpandedPrincipal>)) foundInterface = static_cast <nsIExpandedPrincipal*>(this); else if (aIID.Equals(mozilla ::detail::kImplementedIID<std::remove_reference_t<decltype (*this)>, nsISupports>)) foundInterface = static_cast< nsISupports*>(static_cast<nsIPrincipal*>(this)); else if (aIID.Equals((nsIClassInfo::kIID))) { if (!gExpandedPrincipal_classInfoGlobal ) gExpandedPrincipal_classInfoGlobal = new (kExpandedPrincipalClassInfoDataPlace .addr()) GenericClassInfo(&kExpandedPrincipalClassInfoData ); foundInterface = gExpandedPrincipal_classInfoGlobal; } else foundInterface = 0; nsresult status; if (!foundInterface) { do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aIID.Equals((nsISupports::kIID)))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aIID.Equals((nsISupports::kIID ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!aIID.Equals((nsISupports::kIID))", "./../../caps/ExpandedPrincipal.cpp" , 22); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::kIID))" ")"); do { MOZ_CrashSequence(__null, 22); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE ; } else { (foundInterface)->AddRef(); status = NS_OK; } * aInstancePtr = foundInterface; return status; } |
| 23 | NS_IMPL_CI_INTERFACE_GETTER(ExpandedPrincipal, nsIPrincipal,static_assert(2 > 0, "Need more arguments to NS_IMPL_CI_INTERFACE_GETTER" ); nsresult ExpandedPrincipal_GetInterfacesHelper(nsTArray< nsIID> & array) { array.Clear(); array.SetCapacity(2); array.AppendElement((nsIPrincipal::kIID)); array.AppendElement ((nsIExpandedPrincipal::kIID)); return NS_OK; } |
| 24 | nsIExpandedPrincipal)static_assert(2 > 0, "Need more arguments to NS_IMPL_CI_INTERFACE_GETTER" ); nsresult ExpandedPrincipal_GetInterfacesHelper(nsTArray< nsIID> & array) { array.Clear(); array.SetCapacity(2); array.AppendElement((nsIPrincipal::kIID)); array.AppendElement ((nsIExpandedPrincipal::kIID)); return NS_OK; } |
| 25 | |
| 26 | ExpandedPrincipal::ExpandedPrincipal( |
| 27 | nsTArray<nsCOMPtr<nsIPrincipal>>&& aPrincipals, |
| 28 | const nsACString& aOriginNoSuffix, const OriginAttributes& aAttrs) |
| 29 | : BasePrincipal(eExpandedPrincipal, aOriginNoSuffix, aAttrs), |
| 30 | mPrincipals(std::move(aPrincipals)) {} |
| 31 | |
| 32 | ExpandedPrincipal::~ExpandedPrincipal() = default; |
| 33 | |
| 34 | already_AddRefed<ExpandedPrincipal> ExpandedPrincipal::Create( |
| 35 | const nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList, |
| 36 | const OriginAttributes& aAttrs) { |
| 37 | nsTArray<nsCOMPtr<nsIPrincipal>> principals; |
| 38 | for (size_t i = 0; i < aAllowList.Length(); ++i) { |
| 39 | principals.AppendElement(aAllowList[i]); |
| 40 | } |
| 41 | |
| 42 | nsAutoCString origin; |
| 43 | origin.AssignLiteral("[Expanded Principal ["); |
| 44 | StringJoinAppend( |
| 45 | origin, ", "_ns, principals, |
| 46 | [](nsACString& dest, const nsCOMPtr<nsIPrincipal>& principal) { |
| 47 | nsAutoCString subOrigin; |
| 48 | DebugOnly<nsresult> rv = principal->GetOrigin(subOrigin); |
| 49 | MOZ_ASSERT(NS_SUCCEEDED(rv))do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "./../../caps/ExpandedPrincipal.cpp" , 49); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ")"); do { MOZ_CrashSequence(__null, 49); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 50 | dest.Append(subOrigin); |
| 51 | }); |
| 52 | origin.AppendLiteral("]]"); |
| 53 | |
| 54 | RefPtr<ExpandedPrincipal> ep = |
| 55 | new ExpandedPrincipal(std::move(principals), origin, aAttrs); |
| 56 | return ep.forget(); |
| 57 | } |
| 58 | |
| 59 | NS_IMETHODIMPnsresult |
| 60 | ExpandedPrincipal::GetDomain(nsIURI** aDomain) { |
| 61 | *aDomain = nullptr; |
| 62 | return NS_OK; |
| 63 | } |
| 64 | |
| 65 | NS_IMETHODIMPnsresult |
| 66 | ExpandedPrincipal::SetDomain(nsIURI* aDomain) { return NS_OK; } |
| 67 | |
| 68 | bool ExpandedPrincipal::SubsumesInternal( |
| 69 | nsIPrincipal* aOther, |
| 70 | BasePrincipal::DocumentDomainConsideration aConsideration) { |
| 71 | // If aOther is an ExpandedPrincipal too, we break it down into its component |
| 72 | // nsIPrincipals, and check subsumes on each one. |
| 73 | if (Cast(aOther)->Is<ExpandedPrincipal>()) { |
| 74 | auto* expanded = Cast(aOther)->As<ExpandedPrincipal>(); |
| 75 | |
| 76 | for (auto& other : expanded->AllowList()) { |
| 77 | // Use SubsumesInternal rather than Subsumes here, since OriginAttribute |
| 78 | // checks are only done between non-expanded sub-principals, and we don't |
| 79 | // need to incur the extra virtual call overhead. |
| 80 | if (!SubsumesInternal(other, aConsideration)) { |
| 81 | return false; |
| 82 | } |
| 83 | } |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | // We're dealing with a regular principal. One of our principals must subsume |
| 88 | // it. |
| 89 | for (uint32_t i = 0; i < mPrincipals.Length(); ++i) { |
| 90 | if (Cast(mPrincipals[i])->Subsumes(aOther, aConsideration)) { |
| 91 | return true; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | bool ExpandedPrincipal::MayLoadInternal(nsIURI* uri) { |
| 99 | for (uint32_t i = 0; i < mPrincipals.Length(); ++i) { |
| 100 | if (BasePrincipal::Cast(mPrincipals[i])->MayLoadInternal(uri)) { |
| 101 | return true; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | NS_IMETHODIMPnsresult |
| 109 | ExpandedPrincipal::GetURI(nsIURI** aURI) { |
| 110 | *aURI = nullptr; |
| 111 | return NS_OK; |
| 112 | } |
| 113 | |
| 114 | const nsTArray<nsCOMPtr<nsIPrincipal>>& ExpandedPrincipal::AllowList() { |
| 115 | return mPrincipals; |
| 116 | } |
| 117 | |
| 118 | NS_IMETHODIMPnsresult |
| 119 | ExpandedPrincipal::GetBaseDomain(nsACString& aBaseDomain) { |
| 120 | return NS_ERROR_NOT_AVAILABLE; |
| 121 | } |
| 122 | |
| 123 | NS_IMETHODIMPnsresult |
| 124 | ExpandedPrincipal::GetAddonId(nsAString& aAddonId) { |
| 125 | aAddonId.Truncate(); |
| 126 | return NS_OK; |
| 127 | }; |
| 128 | |
| 129 | bool ExpandedPrincipal::AddonHasPermission(const nsAtom* aPerm) { |
| 130 | for (size_t i = 0; i < mPrincipals.Length(); ++i) { |
| 131 | if (BasePrincipal::Cast(mPrincipals[i])->AddonHasPermission(aPerm)) { |
| 132 | return true; |
| 133 | } |
| 134 | } |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | bool ExpandedPrincipal::AddonAllowsLoad(nsIURI* aURI, |
| 139 | bool aExplicit /* = false */) { |
| 140 | for (const auto& principal : mPrincipals) { |
| 141 | if (Cast(principal)->AddonAllowsLoad(aURI, aExplicit)) { |
| 142 | return true; |
| 143 | } |
| 144 | } |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | void ExpandedPrincipal::SetCsp(nsIContentSecurityPolicy* aCSP) { |
| 149 | AssertIsOnMainThread(); |
| 150 | mCSP = new nsMainThreadPtrHolder<nsIContentSecurityPolicy>( |
| 151 | "ExpandedPrincipal::mCSP", aCSP); |
| 152 | } |
| 153 | |
| 154 | NS_IMETHODIMPnsresult |
| 155 | ExpandedPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp) { |
| 156 | AssertIsOnMainThread(); |
| 157 | NS_IF_ADDREF(*aCsp = mCSP)ns_if_addref(*aCsp = mCSP); |
| 158 | return NS_OK; |
| 159 | } |
| 160 | |
| 161 | nsIPrincipal* ExpandedPrincipal::PrincipalToInherit(nsIURI* aRequestedURI) { |
| 162 | if (aRequestedURI) { |
| 163 | // If a given sub-principal subsumes the given URI, use that principal for |
| 164 | // inheritance. In general, this only happens with certain CORS modes, loads |
| 165 | // with forced principal inheritance, and creation of XML documents from |
| 166 | // XMLHttpRequests or fetch requests. For URIs that normally inherit a |
| 167 | // principal (such as data: URIs), we fall back to the last principal in the |
| 168 | // allowlist. |
| 169 | for (const auto& principal : mPrincipals) { |
| 170 | if (Cast(principal)->MayLoadInternal(aRequestedURI)) { |
| 171 | return principal; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | return mPrincipals.LastElement(); |
| 176 | } |
| 177 | |
| 178 | nsresult ExpandedPrincipal::GetScriptLocation(nsACString& aStr) { |
| 179 | aStr.AssignLiteral("[Expanded Principal ["); |
| 180 | for (size_t i = 0; i < mPrincipals.Length(); ++i) { |
| 181 | if (i != 0) { |
| 182 | aStr.AppendLiteral(", "); |
| 183 | } |
| 184 | |
| 185 | nsAutoCString spec; |
| 186 | nsresult rv = |
| 187 | nsJSPrincipals::get(mPrincipals.ElementAt(i))->GetScriptLocation(spec); |
| 188 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../caps/ExpandedPrincipal.cpp" , 188); return rv; } } while (false); |
| 189 | |
| 190 | aStr.Append(spec); |
| 191 | } |
| 192 | aStr.AppendLiteral("]]"); |
| 193 | return NS_OK; |
| 194 | } |
| 195 | |
| 196 | ////////////////////////////////////////// |
| 197 | // Methods implementing nsISerializable // |
| 198 | ////////////////////////////////////////// |
| 199 | |
| 200 | // We've had way too many issues with unversioned serializations, so |
| 201 | // explicitly version this one. |
| 202 | static const uint32_t kSerializationVersion = 1; |
| 203 | |
| 204 | NS_IMETHODIMPnsresult |
| 205 | ExpandedPrincipal::Deserializer::Read(nsIObjectInputStream* aStream) { |
| 206 | uint32_t version; |
| 207 | nsresult rv = aStream->Read32(&version); |
Value stored to 'rv' during its initialization is never read | |
| 208 | if (version != kSerializationVersion) { |
| 209 | MOZ_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "We really need to add handling of the old(?) version here" ")", "./../../caps/ExpandedPrincipal.cpp", 210); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "We really need to add handling of the old(?) version here" ")"); do { MOZ_CrashSequence(__null, 210); __attribute__((nomerge )) ::abort(); } while (false); } } while (false) |
| 210 | "We really need to add handling of the old(?) version here")do { static_assert( mozilla::detail::AssertionConditionType< decltype(false)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("false" " (" "We really need to add handling of the old(?) version here" ")", "./../../caps/ExpandedPrincipal.cpp", 210); AnnotateMozCrashReason ("MOZ_ASSERT" "(" "false" ") (" "We really need to add handling of the old(?) version here" ")"); do { MOZ_CrashSequence(__null, 210); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 211 | return NS_ERROR_UNEXPECTED; |
| 212 | } |
| 213 | |
| 214 | uint32_t count; |
| 215 | rv = aStream->Read32(&count); |
| 216 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 217 | return rv; |
| 218 | } |
| 219 | |
| 220 | nsTArray<nsCOMPtr<nsIPrincipal>> principals; |
| 221 | if (!principals.SetCapacity(count, fallible)) { |
| 222 | return NS_ERROR_OUT_OF_MEMORY; |
| 223 | } |
| 224 | |
| 225 | for (uint32_t i = 0; i < count; ++i) { |
| 226 | nsCOMPtr<nsISupports> read; |
| 227 | rv = aStream->ReadObject(true, getter_AddRefs(read)); |
| 228 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 229 | return rv; |
| 230 | } |
| 231 | |
| 232 | nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(read); |
| 233 | if (!principal) { |
| 234 | return NS_ERROR_UNEXPECTED; |
| 235 | } |
| 236 | |
| 237 | principals.AppendElement(std::move(principal)); |
| 238 | } |
| 239 | |
| 240 | mPrincipal = ExpandedPrincipal::Create(principals, OriginAttributes()); |
| 241 | return NS_OK; |
| 242 | } |
| 243 | |
| 244 | nsresult ExpandedPrincipal::GetSiteIdentifier(SiteIdentifier& aSite) { |
| 245 | // Call GetSiteIdentifier on each of our principals and return a new |
| 246 | // ExpandedPrincipal. |
| 247 | |
| 248 | nsTArray<nsCOMPtr<nsIPrincipal>> allowlist; |
| 249 | for (const auto& principal : mPrincipals) { |
| 250 | SiteIdentifier site; |
| 251 | nsresult rv = Cast(principal)->GetSiteIdentifier(site); |
| 252 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../caps/ExpandedPrincipal.cpp" , 252); return rv; } } while (false); |
| 253 | allowlist.AppendElement(site.GetPrincipal()); |
| 254 | } |
| 255 | |
| 256 | RefPtr<ExpandedPrincipal> expandedPrincipal = |
| 257 | ExpandedPrincipal::Create(allowlist, OriginAttributesRef()); |
| 258 | MOZ_ASSERT(expandedPrincipal, "ExpandedPrincipal::Create returned nullptr?")do { static_assert( mozilla::detail::AssertionConditionType< decltype(expandedPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(expandedPrincipal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("expandedPrincipal" " (" "ExpandedPrincipal::Create returned nullptr?" ")", "./../../caps/ExpandedPrincipal.cpp" , 258); AnnotateMozCrashReason("MOZ_ASSERT" "(" "expandedPrincipal" ") (" "ExpandedPrincipal::Create returned nullptr?" ")"); do { MOZ_CrashSequence(__null, 258); __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 259 | |
| 260 | aSite.Init(expandedPrincipal); |
| 261 | return NS_OK; |
| 262 | } |
| 263 | |
| 264 | nsresult ExpandedPrincipal::WriteJSONInnerProperties(JSONWriter& aWriter) { |
| 265 | aWriter.StartArrayProperty(JSONEnumKeyString<eSpecs>(), |
| 266 | JSONWriter::CollectionStyle::SingleLineStyle); |
| 267 | |
| 268 | for (const auto& principal : mPrincipals) { |
| 269 | aWriter.StartObjectElement(JSONWriter::CollectionStyle::SingleLineStyle); |
| 270 | |
| 271 | nsresult rv = BasePrincipal::Cast(principal)->WriteJSONProperties(aWriter); |
| 272 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../caps/ExpandedPrincipal.cpp" , 272); return rv; } } while (false); |
| 273 | |
| 274 | aWriter.EndObject(); |
| 275 | } |
| 276 | |
| 277 | aWriter.EndArray(); |
| 278 | |
| 279 | nsAutoCString suffix; |
| 280 | OriginAttributesRef().CreateSuffix(suffix); |
| 281 | if (suffix.Length() > 0) { |
| 282 | WriteJSONProperty<eSuffix>(aWriter, suffix); |
| 283 | } |
| 284 | |
| 285 | return NS_OK; |
| 286 | } |
| 287 | |
| 288 | bool ExpandedPrincipalJSONHandler::ProcessSubsumedResult(bool aResult) { |
| 289 | if (!aResult) { |
| 290 | NS_WARNING("Failed to parse subsumed principal")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to parse subsumed principal" , nullptr, "./../../caps/ExpandedPrincipal.cpp", 290); |
| 291 | mState = State::Error; |
| 292 | return false; |
| 293 | } |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | bool ExpandedPrincipalJSONHandler::startObject() { |
| 298 | if (mSubsumedHandler.isSome()) { |
| 299 | return ProcessSubsumedResult(mSubsumedHandler->startObject()); |
| 300 | } |
| 301 | |
| 302 | switch (mState) { |
| 303 | case State::Init: |
| 304 | mState = State::StartObject; |
| 305 | break; |
| 306 | case State::StartArray: |
| 307 | mState = State::SubsumedPrincipal; |
| 308 | [[fallthrough]]; |
| 309 | case State::SubsumedPrincipal: |
| 310 | mSubsumedHandler.emplace(); |
| 311 | |
| 312 | return ProcessSubsumedResult(mSubsumedHandler->startObject()); |
| 313 | default: |
| 314 | NS_WARNING("Unexpected object value")NS_DebugBreak(NS_DEBUG_WARNING, "Unexpected object value", nullptr , "./../../caps/ExpandedPrincipal.cpp", 314); |
| 315 | mState = State::Error; |
| 316 | return false; |
| 317 | } |
| 318 | |
| 319 | return true; |
| 320 | } |
| 321 | |
| 322 | bool ExpandedPrincipalJSONHandler::propertyName(const JS::Latin1Char* name, |
| 323 | size_t length) { |
| 324 | if (mSubsumedHandler.isSome()) { |
| 325 | return ProcessSubsumedResult(mSubsumedHandler->propertyName(name, length)); |
| 326 | } |
| 327 | |
| 328 | switch (mState) { |
| 329 | case State::StartObject: |
| 330 | case State::AfterPropertyValue: { |
| 331 | if (length != 1) { |
| 332 | NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString("Unexpected property name length: %zu" , length) .get(), nullptr, "./../../caps/ExpandedPrincipal.cpp" , 334) |
| 333 | nsPrintfCString("Unexpected property name length: %zu", length)NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString("Unexpected property name length: %zu" , length) .get(), nullptr, "./../../caps/ExpandedPrincipal.cpp" , 334) |
| 334 | .get())NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString("Unexpected property name length: %zu" , length) .get(), nullptr, "./../../caps/ExpandedPrincipal.cpp" , 334); |
| 335 | mState = State::Error; |
| 336 | return false; |
| 337 | } |
| 338 | |
| 339 | char key = char(name[0]); |
| 340 | switch (key) { |
| 341 | case ExpandedPrincipal::SpecsKey: |
| 342 | mState = State::SpecsKey; |
| 343 | break; |
| 344 | case ExpandedPrincipal::SuffixKey: |
| 345 | mState = State::SuffixKey; |
| 346 | break; |
| 347 | default: |
| 348 | NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString("Unexpected property name: '%c'" , key).get(), nullptr, "./../../caps/ExpandedPrincipal.cpp", 349 ) |
| 349 | nsPrintfCString("Unexpected property name: '%c'", key).get())NS_DebugBreak(NS_DEBUG_WARNING, nsPrintfCString("Unexpected property name: '%c'" , key).get(), nullptr, "./../../caps/ExpandedPrincipal.cpp", 349 ); |
| 350 | mState = State::Error; |
| 351 | return false; |
| 352 | } |
| 353 | break; |
| 354 | } |
| 355 | default: |
| 356 | NS_WARNING("Unexpected property name")NS_DebugBreak(NS_DEBUG_WARNING, "Unexpected property name", nullptr , "./../../caps/ExpandedPrincipal.cpp", 356); |
| 357 | mState = State::Error; |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | return true; |
| 362 | } |
| 363 | |
| 364 | bool ExpandedPrincipalJSONHandler::endObject() { |
| 365 | if (mSubsumedHandler.isSome()) { |
| 366 | if (!ProcessSubsumedResult(mSubsumedHandler->endObject())) { |
| 367 | return false; |
| 368 | } |
| 369 | if (mSubsumedHandler->HasAccepted()) { |
| 370 | nsCOMPtr<nsIPrincipal> principal = mSubsumedHandler->mPrincipal.forget(); |
| 371 | mSubsumedHandler.reset(); |
| 372 | mAllowList.AppendElement(principal); |
| 373 | } |
| 374 | return true; |
| 375 | } |
| 376 | |
| 377 | switch (mState) { |
| 378 | case State::AfterPropertyValue: |
| 379 | mPrincipal = ExpandedPrincipal::Create(mAllowList, mAttrs); |
| 380 | MOZ_ASSERT(mPrincipal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(mPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(mPrincipal))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("mPrincipal", "./../../caps/ExpandedPrincipal.cpp" , 380); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPrincipal" ")" ); do { MOZ_CrashSequence(__null, 380); __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 381 | |
| 382 | mState = State::EndObject; |
| 383 | break; |
| 384 | default: |
| 385 | NS_WARNING("Unexpected end of object")NS_DebugBreak(NS_DEBUG_WARNING, "Unexpected end of object", nullptr , "./../../caps/ExpandedPrincipal.cpp", 385); |
| 386 | mState = State::Error; |
| 387 | return false; |
| 388 | } |
| 389 | |
| 390 | return true; |
| 391 | } |
| 392 | |
| 393 | bool ExpandedPrincipalJSONHandler::startArray() { |
| 394 | switch (mState) { |
| 395 | case State::SpecsKey: |
| 396 | mState = State::StartArray; |
| 397 | break; |
| 398 | default: |
| 399 | NS_WARNING("Unexpected array value")NS_DebugBreak(NS_DEBUG_WARNING, "Unexpected array value", nullptr , "./../../caps/ExpandedPrincipal.cpp", 399); |
| 400 | mState = State::Error; |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | return true; |
| 405 | } |
| 406 | |
| 407 | bool ExpandedPrincipalJSONHandler::endArray() { |
| 408 | switch (mState) { |
| 409 | case State::SubsumedPrincipal: { |
| 410 | mState = State::AfterPropertyValue; |
| 411 | break; |
| 412 | } |
| 413 | default: |
| 414 | NS_WARNING("Unexpected end of array")NS_DebugBreak(NS_DEBUG_WARNING, "Unexpected end of array", nullptr , "./../../caps/ExpandedPrincipal.cpp", 414); |
| 415 | mState = State::Error; |
| 416 | return false; |
| 417 | } |
| 418 | |
| 419 | return true; |
| 420 | } |
| 421 | |
| 422 | bool ExpandedPrincipalJSONHandler::stringValue(const JS::Latin1Char* str, |
| 423 | size_t length) { |
| 424 | if (mSubsumedHandler.isSome()) { |
| 425 | return ProcessSubsumedResult(mSubsumedHandler->stringValue(str, length)); |
| 426 | } |
| 427 | |
| 428 | switch (mState) { |
| 429 | case State::SpecsKey: { |
| 430 | nsDependentCSubstring specs(reinterpret_cast<const char*>(str), length); |
| 431 | |
| 432 | for (const nsACString& each : specs.Split(',')) { |
| 433 | nsAutoCString result; |
| 434 | nsresult rv = Base64Decode(each, result); |
| 435 | MOZ_ASSERT(NS_SUCCEEDED(rv), "failed to decode")do { static_assert( mozilla::detail::AssertionConditionType< decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) )))>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1) ))))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" " (" "failed to decode" ")", "./../../caps/ExpandedPrincipal.cpp" , 435); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))" ") (" "failed to decode" ")"); do { MOZ_CrashSequence(__null , 435); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 436 | if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) { |
| 437 | mState = State::Error; |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | nsCOMPtr<nsIPrincipal> principal = BasePrincipal::FromJSON(result); |
| 442 | if (!principal) { |
| 443 | mState = State::Error; |
| 444 | return false; |
| 445 | } |
| 446 | mAllowList.AppendElement(principal); |
| 447 | } |
| 448 | |
| 449 | mState = State::AfterPropertyValue; |
| 450 | break; |
| 451 | } |
| 452 | case State::SuffixKey: { |
| 453 | nsDependentCSubstring attrs(reinterpret_cast<const char*>(str), length); |
| 454 | if (!mAttrs.PopulateFromSuffix(attrs)) { |
| 455 | mState = State::Error; |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | mState = State::AfterPropertyValue; |
| 460 | break; |
| 461 | } |
| 462 | default: |
| 463 | NS_WARNING("Unexpected string value")NS_DebugBreak(NS_DEBUG_WARNING, "Unexpected string value", nullptr , "./../../caps/ExpandedPrincipal.cpp", 463); |
| 464 | mState = State::Error; |
| 465 | return false; |
| 466 | } |
| 467 | |
| 468 | return true; |
| 469 | } |
| 470 | |
| 471 | NS_IMETHODIMPnsresult |
| 472 | ExpandedPrincipal::IsThirdPartyURI(nsIURI* aURI, bool* aRes) { |
| 473 | // ExpandedPrincipal for extension content scripts consist of two principals, |
| 474 | // the document's principal and the extension's principal. |
| 475 | // To make sure that the third-party check behaves like the web page on which |
| 476 | // the content script is running, ignore the extension's principal. |
| 477 | |
| 478 | for (const auto& principal : mPrincipals) { |
| 479 | if (!Cast(principal)->AddonPolicyCore()) { |
| 480 | return Cast(principal)->IsThirdPartyURI(aURI, aRes); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | if (mPrincipals.IsEmpty()) { |
| 485 | *aRes = true; |
| 486 | return NS_OK; |
| 487 | } |
| 488 | |
| 489 | return Cast(mPrincipals[0])->IsThirdPartyURI(aURI, aRes); |
| 490 | } |