Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp
Warning:line 527, column 7
Value stored to 'rv' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_ipc_glue0.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/glue -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/glue -resource-dir /usr/lib/llvm-18/lib/clang/18 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D HAVE_UINT64_T -D WEBRTC_MOZILLA_BUILD -D RTC_ENABLE_VP9 -D WEBRTC_POSIX -D WEBRTC_BUILD_LIBEVENT -D WEBRTC_LINUX -D WEBRTC_USE_PIPEWIRE -D WEBRTC_USE_X11 -D MOZ_CHILD_PROCESS_NAME="plugin-container" -D MOZ_CHILD_PROCESS_BUNDLENAME="plugin-container.app" -D MOZ_EME_PROCESS_NAME_BRANDED="Nightly Media Plugin Helper" -D MOZ_EME_PROCESS_BUNDLENAME="media-plugin-helper.app" -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/glue -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/glue -I /var/lib/jenkins/workspace/firefox-scan-build/caps -I /var/lib/jenkins/workspace/firefox-scan-build/dom/broadcastchannel -I /var/lib/jenkins/workspace/firefox-scan-build/dom/indexedDB -I /var/lib/jenkins/workspace/firefox-scan-build/dom/storage -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/base -I /var/lib/jenkins/workspace/firefox-scan-build/third_party/libwebrtc -I /var/lib/jenkins/workspace/firefox-scan-build/third_party/libwebrtc/third_party/abseil-cpp -I /var/lib/jenkins/workspace/firefox-scan-build/tools/fuzzing/ipc -I /var/lib/jenkins/workspace/firefox-scan-build/xpcom/build -I /var/lib/jenkins/workspace/firefox-scan-build/dom/ipc -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/crashreporter -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre -I /var/lib/jenkins/workspace/firefox-scan-build/xpcom/base -I /var/lib/jenkins/workspace/firefox-scan-build/xpcom/threads -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-05-16-034744-15991-1 -x c++ Unified_cpp_ipc_glue0.cpp
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#include "BackgroundUtils.h"
8
9#include "MainThreadUtils.h"
10#include "mozilla/Assertions.h"
11#include "mozilla/BasePrincipal.h"
12#include "mozilla/ContentPrincipal.h"
13#include "mozilla/NullPrincipal.h"
14#include "mozilla/SystemPrincipal.h"
15#include "mozilla/ipc/PBackgroundSharedTypes.h"
16#include "mozilla/ipc/URIUtils.h"
17#include "mozilla/net/CookieJarSettings.h"
18#include "mozilla/net/InterceptionInfo.h"
19#include "mozilla/net/NeckoChannelParams.h"
20#include "ExpandedPrincipal.h"
21#include "nsIScriptSecurityManager.h"
22#include "nsIURI.h"
23#include "nsNetUtil.h"
24#include "mozilla/LoadInfo.h"
25#include "nsContentUtils.h"
26#include "nsString.h"
27#include "nsTArray.h"
28#include "mozilla/nsRedirectHistoryEntry.h"
29#include "mozilla/dom/nsCSPUtils.h"
30#include "mozilla/dom/nsCSPContext.h"
31#include "mozilla/dom/BrowsingContext.h"
32#include "mozilla/dom/CanonicalBrowsingContext.h"
33#include "mozilla/dom/Document.h"
34#include "mozilla/dom/WindowGlobalParent.h"
35#include "mozilla/LoadInfo.h"
36
37using namespace mozilla::dom;
38using namespace mozilla::net;
39
40namespace mozilla {
41
42namespace ipc {
43
44Result<nsCOMPtr<nsIPrincipal>, nsresult> PrincipalInfoToPrincipal(
45 const PrincipalInfo& aPrincipalInfo) {
46 MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPrincipalInfo.type() != PrincipalInfo::T__None)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aPrincipalInfo.type() != PrincipalInfo::T__None))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aPrincipalInfo.type() != PrincipalInfo::T__None"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 46); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipalInfo.type() != PrincipalInfo::T__None"
")"); do { *((volatile int*)__null) = 46; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
47
48 nsCOMPtr<nsIPrincipal> principal;
49 nsresult rv;
50
51 switch (aPrincipalInfo.type()) {
52 case PrincipalInfo::TSystemPrincipalInfo: {
53 principal = SystemPrincipal::Get();
54 if (NS_WARN_IF(!principal)NS_warn_if_impl(!principal, "!principal", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 54)
) {
55 return Err(NS_ERROR_NOT_INITIALIZED);
56 }
57
58 return principal;
59 }
60
61 case PrincipalInfo::TNullPrincipalInfo: {
62 const NullPrincipalInfo& info = aPrincipalInfo.get_NullPrincipalInfo();
63
64 nsCOMPtr<nsIURI> uri;
65 rv = NS_NewURI(getter_AddRefs(uri), info.spec());
66 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 66)
) {
67 return Err(rv);
68 }
69
70 if (!uri->SchemeIs(NS_NULLPRINCIPAL_SCHEME"moz-nullprincipal")) {
71 return Err(NS_ERROR_ILLEGAL_VALUE);
72 }
73
74 principal = NullPrincipal::Create(info.attrs(), uri);
75 return principal;
76 }
77
78 case PrincipalInfo::TContentPrincipalInfo: {
79 const ContentPrincipalInfo& info =
80 aPrincipalInfo.get_ContentPrincipalInfo();
81
82 nsCOMPtr<nsIURI> uri;
83 rv = NS_NewURI(getter_AddRefs(uri), info.spec());
84 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 84)
) {
85 return Err(rv);
86 }
87
88 nsCOMPtr<nsIURI> domain;
89 if (info.domain()) {
90 rv = NS_NewURI(getter_AddRefs(domain), *info.domain());
91 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 91)
) {
92 return Err(rv);
93 }
94 }
95
96 principal =
97 BasePrincipal::CreateContentPrincipal(uri, info.attrs(), domain);
98 if (NS_WARN_IF(!principal)NS_warn_if_impl(!principal, "!principal", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 98)
) {
99 return Err(NS_ERROR_NULL_POINTER);
100 }
101
102 // Origin must match what the_new_principal.getOrigin returns.
103 nsAutoCString originNoSuffix;
104 rv = principal->GetOriginNoSuffix(originNoSuffix);
105 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 105)
) {
106 return Err(rv);
107 }
108
109 if (NS_WARN_IF(!info.originNoSuffix().Equals(originNoSuffix))NS_warn_if_impl(!info.originNoSuffix().Equals(originNoSuffix)
, "!info.originNoSuffix().Equals(originNoSuffix)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 109)
) {
110 return Err(NS_ERROR_FAILURE);
111 }
112
113 if (!info.baseDomain().IsVoid()) {
114 nsAutoCString baseDomain;
115 rv = principal->GetBaseDomain(baseDomain);
116 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 116)
) {
117 return Err(rv);
118 }
119
120 if (NS_WARN_IF(!info.baseDomain().Equals(baseDomain))NS_warn_if_impl(!info.baseDomain().Equals(baseDomain), "!info.baseDomain().Equals(baseDomain)"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 120)
) {
121 return Err(NS_ERROR_FAILURE);
122 }
123 }
124 return principal;
125 }
126
127 case PrincipalInfo::TExpandedPrincipalInfo: {
128 const ExpandedPrincipalInfo& info =
129 aPrincipalInfo.get_ExpandedPrincipalInfo();
130
131 nsTArray<nsCOMPtr<nsIPrincipal>> allowlist;
132 nsCOMPtr<nsIPrincipal> alPrincipal;
133
134 for (uint32_t i = 0; i < info.allowlist().Length(); i++) {
135 auto principalOrErr = PrincipalInfoToPrincipal(info.allowlist()[i]);
136 if (NS_WARN_IF(principalOrErr.isErr())NS_warn_if_impl(principalOrErr.isErr(), "principalOrErr.isErr()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 136)
) {
137 nsresult ret = principalOrErr.unwrapErr();
138 return Err(ret);
139 }
140 // append that principal to the allowlist
141 allowlist.AppendElement(principalOrErr.unwrap());
142 }
143
144 RefPtr<ExpandedPrincipal> expandedPrincipal =
145 ExpandedPrincipal::Create(allowlist, info.attrs());
146 if (!expandedPrincipal) {
147 return Err(NS_ERROR_FAILURE);
148 }
149
150 principal = expandedPrincipal;
151 return principal;
152 }
153
154 default:
155 return Err(NS_ERROR_FAILURE);
156 }
157}
158
159bool StorageKeysEqual(const PrincipalInfo& aLeft, const PrincipalInfo& aRight) {
160 MOZ_RELEASE_ASSERT(aLeft.type() == PrincipalInfo::TContentPrincipalInfo ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aLeft.type() == PrincipalInfo::TContentPrincipalInfo
|| aLeft.type() == PrincipalInfo::TSystemPrincipalInfo)>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aLeft.type() == PrincipalInfo::TContentPrincipalInfo
|| aLeft.type() == PrincipalInfo::TSystemPrincipalInfo))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aLeft.type() == PrincipalInfo::TContentPrincipalInfo || aLeft.type() == PrincipalInfo::TSystemPrincipalInfo"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 161); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "aLeft.type() == PrincipalInfo::TContentPrincipalInfo || aLeft.type() == PrincipalInfo::TSystemPrincipalInfo"
")"); do { *((volatile int*)__null) = 161; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
161 aLeft.type() == PrincipalInfo::TSystemPrincipalInfo)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aLeft.type() == PrincipalInfo::TContentPrincipalInfo
|| aLeft.type() == PrincipalInfo::TSystemPrincipalInfo)>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aLeft.type() == PrincipalInfo::TContentPrincipalInfo
|| aLeft.type() == PrincipalInfo::TSystemPrincipalInfo))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aLeft.type() == PrincipalInfo::TContentPrincipalInfo || aLeft.type() == PrincipalInfo::TSystemPrincipalInfo"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 161); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "aLeft.type() == PrincipalInfo::TContentPrincipalInfo || aLeft.type() == PrincipalInfo::TSystemPrincipalInfo"
")"); do { *((volatile int*)__null) = 161; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
162 MOZ_RELEASE_ASSERT(aRight.type() == PrincipalInfo::TContentPrincipalInfo ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aRight.type() == PrincipalInfo::TContentPrincipalInfo
|| aRight.type() == PrincipalInfo::TSystemPrincipalInfo)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aRight.type() == PrincipalInfo::TContentPrincipalInfo
|| aRight.type() == PrincipalInfo::TSystemPrincipalInfo))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aRight.type() == PrincipalInfo::TContentPrincipalInfo || aRight.type() == PrincipalInfo::TSystemPrincipalInfo"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 163); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "aRight.type() == PrincipalInfo::TContentPrincipalInfo || aRight.type() == PrincipalInfo::TSystemPrincipalInfo"
")"); do { *((volatile int*)__null) = 163; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
163 aRight.type() == PrincipalInfo::TSystemPrincipalInfo)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aRight.type() == PrincipalInfo::TContentPrincipalInfo
|| aRight.type() == PrincipalInfo::TSystemPrincipalInfo)>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aRight.type() == PrincipalInfo::TContentPrincipalInfo
|| aRight.type() == PrincipalInfo::TSystemPrincipalInfo))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aRight.type() == PrincipalInfo::TContentPrincipalInfo || aRight.type() == PrincipalInfo::TSystemPrincipalInfo"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 163); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "aRight.type() == PrincipalInfo::TContentPrincipalInfo || aRight.type() == PrincipalInfo::TSystemPrincipalInfo"
")"); do { *((volatile int*)__null) = 163; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
164
165 if (aLeft.type() != aRight.type()) {
166 return false;
167 }
168
169 if (aLeft.type() == PrincipalInfo::TContentPrincipalInfo) {
170 const ContentPrincipalInfo& leftContent = aLeft.get_ContentPrincipalInfo();
171 const ContentPrincipalInfo& rightContent =
172 aRight.get_ContentPrincipalInfo();
173
174 return leftContent.attrs() == rightContent.attrs() &&
175 leftContent.originNoSuffix() == rightContent.originNoSuffix();
176 }
177
178 // Storage keys for the System principal always equal.
179 return true;
180}
181
182already_AddRefed<nsIContentSecurityPolicy> CSPInfoToCSP(
183 const CSPInfo& aCSPInfo, Document* aRequestingDoc,
184 nsresult* aOptionalResult) {
185 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 185); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 185; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
186
187 nsresult stackResult;
188 nsresult& rv = aOptionalResult ? *aOptionalResult : stackResult;
189
190 RefPtr<nsCSPContext> csp = new nsCSPContext();
191
192 if (aRequestingDoc) {
193 rv = csp->SetRequestContextWithDocument(aRequestingDoc);
194 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 194)
) {
195 return nullptr;
196 }
197 } else {
198 auto principalOrErr =
199 PrincipalInfoToPrincipal(aCSPInfo.requestPrincipalInfo());
200 if (NS_WARN_IF(principalOrErr.isErr())NS_warn_if_impl(principalOrErr.isErr(), "principalOrErr.isErr()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 200)
) {
201 return nullptr;
202 }
203
204 nsCOMPtr<nsIURI> selfURI;
205 if (!aCSPInfo.selfURISpec().IsEmpty()) {
206 rv = NS_NewURI(getter_AddRefs(selfURI), aCSPInfo.selfURISpec());
207 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 207)
) {
208 return nullptr;
209 }
210 }
211
212 nsCOMPtr<nsIPrincipal> principal = principalOrErr.unwrap();
213
214 rv = csp->SetRequestContextWithPrincipal(
215 principal, selfURI, aCSPInfo.referrer(), aCSPInfo.innerWindowID());
216 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 216)
) {
217 return nullptr;
218 }
219 }
220 csp->SetSkipAllowInlineStyleCheck(aCSPInfo.skipAllowInlineStyleCheck());
221
222 for (uint32_t i = 0; i < aCSPInfo.policyInfos().Length(); i++) {
223 csp->AddIPCPolicy(aCSPInfo.policyInfos()[i]);
224 }
225 return csp.forget();
226}
227
228nsresult CSPToCSPInfo(nsIContentSecurityPolicy* aCSP, CSPInfo* aCSPInfo) {
229 MOZ_ASSERT(NS_IsMainThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(NS_IsMainThread())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(NS_IsMainThread()))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("NS_IsMainThread()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 229); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()"
")"); do { *((volatile int*)__null) = 229; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
230 MOZ_ASSERT(aCSP)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCSP)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(aCSP))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("aCSP", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 230); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCSP" ")"); do
{ *((volatile int*)__null) = 230; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
231 MOZ_ASSERT(aCSPInfo)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aCSPInfo)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aCSPInfo))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aCSPInfo", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 231); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aCSPInfo" ")"
); do { *((volatile int*)__null) = 231; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
232
233 if (!aCSP || !aCSPInfo) {
234 return NS_ERROR_FAILURE;
235 }
236
237 nsCOMPtr<nsIPrincipal> requestPrincipal = aCSP->GetRequestPrincipal();
238
239 PrincipalInfo requestingPrincipalInfo;
240 nsresult rv =
241 PrincipalToPrincipalInfo(requestPrincipal, &requestingPrincipalInfo);
242 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 242)
) {
243 return rv;
244 }
245
246 nsCOMPtr<nsIURI> selfURI = aCSP->GetSelfURI();
247 nsAutoCString selfURISpec;
248 if (selfURI) {
249 selfURI->GetSpec(selfURISpec);
250 }
251
252 nsAutoCString referrer;
253 aCSP->GetReferrer(referrer);
254
255 uint64_t windowID = aCSP->GetInnerWindowID();
256 bool skipAllowInlineStyleCheck = aCSP->GetSkipAllowInlineStyleCheck();
257
258 nsTArray<ContentSecurityPolicy> policies;
259 static_cast<nsCSPContext*>(aCSP)->SerializePolicies(policies);
260
261 *aCSPInfo = CSPInfo(std::move(policies), requestingPrincipalInfo, selfURISpec,
262 referrer, windowID, skipAllowInlineStyleCheck);
263 return NS_OK;
264}
265
266nsresult PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
267 PrincipalInfo* aPrincipalInfo,
268 bool aSkipBaseDomain) {
269 MOZ_ASSERT(aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPrincipal)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPrincipal))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 269); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipal" ")"
); do { *((volatile int*)__null) = 269; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
270 MOZ_ASSERT(aPrincipalInfo)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aPrincipalInfo)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aPrincipalInfo))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("aPrincipalInfo"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 270); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aPrincipalInfo"
")"); do { *((volatile int*)__null) = 270; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
271
272 nsresult rv;
273 if (aPrincipal->GetIsNullPrincipal()) {
274 nsAutoCString spec;
275 rv = aPrincipal->GetAsciiSpec(spec);
276 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 276)
) {
277 return rv;
278 }
279
280 *aPrincipalInfo =
281 NullPrincipalInfo(aPrincipal->OriginAttributesRef(), spec);
282 return NS_OK;
283 }
284
285 if (aPrincipal->IsSystemPrincipal()) {
286 *aPrincipalInfo = SystemPrincipalInfo();
287 return NS_OK;
288 }
289
290 // might be an expanded principal
291 auto* basePrin = BasePrincipal::Cast(aPrincipal);
292 if (basePrin->Is<ExpandedPrincipal>()) {
293 auto* expanded = basePrin->As<ExpandedPrincipal>();
294
295 nsTArray<PrincipalInfo> allowlistInfo;
296 PrincipalInfo info;
297
298 for (auto& prin : expanded->AllowList()) {
299 rv = PrincipalToPrincipalInfo(prin, &info, aSkipBaseDomain);
300 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 300)
) {
301 return rv;
302 }
303 // append that spec to the allowlist
304 allowlistInfo.AppendElement(info);
305 }
306
307 *aPrincipalInfo = ExpandedPrincipalInfo(aPrincipal->OriginAttributesRef(),
308 std::move(allowlistInfo));
309 return NS_OK;
310 }
311
312 nsAutoCString spec;
313 rv = aPrincipal->GetAsciiSpec(spec);
314 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 314)
) {
315 return rv;
316 }
317
318 nsCString originNoSuffix;
319 rv = aPrincipal->GetOriginNoSuffix(originNoSuffix);
320 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 320)
) {
321 return rv;
322 }
323
324 nsCOMPtr<nsIURI> domainUri;
325 rv = aPrincipal->GetDomain(getter_AddRefs(domainUri));
326 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 326)
) {
327 return rv;
328 }
329
330 Maybe<nsCString> domain;
331 if (domainUri) {
332 domain.emplace();
333 rv = domainUri->GetSpec(domain.ref());
334 if (NS_WARN_IF(NS_FAILED(rv))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(rv
)), 0))), "NS_FAILED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 334)
) {
335 return rv;
336 }
337 }
338
339 // This attribute is not crucial.
340 nsCString baseDomain;
341 if (aSkipBaseDomain) {
342 baseDomain.SetIsVoid(true);
343 } else {
344 if (NS_FAILED(aPrincipal->GetBaseDomain(baseDomain))((bool)(__builtin_expect(!!(NS_FAILED_impl(aPrincipal->GetBaseDomain
(baseDomain))), 0)))
) {
345 // No warning here. Some principal URLs do not have a base-domain.
346 baseDomain.SetIsVoid(true);
347 }
348 }
349
350 *aPrincipalInfo =
351 ContentPrincipalInfo(aPrincipal->OriginAttributesRef(), originNoSuffix,
352 spec, domain, baseDomain);
353 return NS_OK;
354}
355
356bool IsPrincipalInfoPrivate(const PrincipalInfo& aPrincipalInfo) {
357 if (aPrincipalInfo.type() != ipc::PrincipalInfo::TContentPrincipalInfo) {
358 return false;
359 }
360
361 const ContentPrincipalInfo& info = aPrincipalInfo.get_ContentPrincipalInfo();
362 return !!info.attrs().mPrivateBrowsingId;
363}
364
365already_AddRefed<nsIRedirectHistoryEntry> RHEntryInfoToRHEntry(
366 const RedirectHistoryEntryInfo& aRHEntryInfo) {
367 auto principalOrErr = PrincipalInfoToPrincipal(aRHEntryInfo.principalInfo());
368 if (NS_WARN_IF(principalOrErr.isErr())NS_warn_if_impl(principalOrErr.isErr(), "principalOrErr.isErr()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 368)
) {
369 return nullptr;
370 }
371
372 nsCOMPtr<nsIPrincipal> principal = principalOrErr.unwrap();
373 nsCOMPtr<nsIURI> referrerUri = DeserializeURI(aRHEntryInfo.referrerUri());
374
375 nsCOMPtr<nsIRedirectHistoryEntry> entry = new nsRedirectHistoryEntry(
376 principal, referrerUri, aRHEntryInfo.remoteAddress());
377
378 return entry.forget();
379}
380
381nsresult RHEntryToRHEntryInfo(nsIRedirectHistoryEntry* aRHEntry,
382 RedirectHistoryEntryInfo* aRHEntryInfo) {
383 MOZ_ASSERT(aRHEntry)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aRHEntry)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aRHEntry))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aRHEntry", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 383); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRHEntry" ")"
); do { *((volatile int*)__null) = 383; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
384 MOZ_ASSERT(aRHEntryInfo)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aRHEntryInfo)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aRHEntryInfo))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("aRHEntryInfo", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 384); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRHEntryInfo"
")"); do { *((volatile int*)__null) = 384; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
385
386 nsresult rv;
387 aRHEntry->GetRemoteAddress(aRHEntryInfo->remoteAddress());
388
389 nsCOMPtr<nsIURI> referrerUri;
390 rv = aRHEntry->GetReferrerURI(getter_AddRefs(referrerUri));
391 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 391); return rv; } } while (false)
;
392 SerializeURI(referrerUri, aRHEntryInfo->referrerUri());
393
394 nsCOMPtr<nsIPrincipal> principal;
395 rv = aRHEntry->GetPrincipal(getter_AddRefs(principal));
396 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 396); return rv; } } while (false)
;
397
398 return PrincipalToPrincipalInfo(principal, &aRHEntryInfo->principalInfo());
399}
400
401nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
402 LoadInfoArgs* outLoadInfoArgs) {
403 nsresult rv = NS_OK;
404 Maybe<PrincipalInfo> loadingPrincipalInfo;
405 if (nsIPrincipal* loadingPrin = aLoadInfo->GetLoadingPrincipal()) {
406 loadingPrincipalInfo.emplace();
407 rv = PrincipalToPrincipalInfo(loadingPrin, loadingPrincipalInfo.ptr());
408 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 408); return rv; } } while (false)
;
409 }
410
411 PrincipalInfo triggeringPrincipalInfo;
412 rv = PrincipalToPrincipalInfo(aLoadInfo->TriggeringPrincipal(),
413 &triggeringPrincipalInfo);
414 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 414); return rv; } } while (false)
;
415
416 Maybe<PrincipalInfo> principalToInheritInfo;
417 if (nsIPrincipal* principalToInherit = aLoadInfo->PrincipalToInherit()) {
418 principalToInheritInfo.emplace();
419 rv = PrincipalToPrincipalInfo(principalToInherit,
420 principalToInheritInfo.ptr());
421 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 421); return rv; } } while (false)
;
422 }
423
424 Maybe<PrincipalInfo> topLevelPrincipalInfo;
425 if (nsIPrincipal* topLevenPrin = aLoadInfo->GetTopLevelPrincipal()) {
426 topLevelPrincipalInfo.emplace();
427 rv = PrincipalToPrincipalInfo(topLevenPrin, topLevelPrincipalInfo.ptr());
428 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 428); return rv; } } while (false)
;
429 }
430
431 Maybe<URIParams> optionalResultPrincipalURI;
432 nsCOMPtr<nsIURI> resultPrincipalURI;
433 Unused << aLoadInfo->GetResultPrincipalURI(
434 getter_AddRefs(resultPrincipalURI));
435 if (resultPrincipalURI) {
436 SerializeURI(resultPrincipalURI, optionalResultPrincipalURI);
437 }
438
439 nsCString triggeringRemoteType;
440 rv = aLoadInfo->GetTriggeringRemoteType(triggeringRemoteType);
441 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 441); return rv; } } while (false)
;
442
443 nsTArray<RedirectHistoryEntryInfo> redirectChainIncludingInternalRedirects;
444 for (const nsCOMPtr<nsIRedirectHistoryEntry>& redirectEntry :
445 aLoadInfo->RedirectChainIncludingInternalRedirects()) {
446 RedirectHistoryEntryInfo* entry =
447 redirectChainIncludingInternalRedirects.AppendElement();
448 rv = RHEntryToRHEntryInfo(redirectEntry, entry);
449 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 449); return rv; } } while (false)
;
450 }
451
452 nsTArray<RedirectHistoryEntryInfo> redirectChain;
453 for (const nsCOMPtr<nsIRedirectHistoryEntry>& redirectEntry :
454 aLoadInfo->RedirectChain()) {
455 RedirectHistoryEntryInfo* entry = redirectChain.AppendElement();
456 rv = RHEntryToRHEntryInfo(redirectEntry, entry);
457 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 457); return rv; } } while (false)
;
458 }
459
460 Maybe<IPCClientInfo> ipcClientInfo;
461 const Maybe<ClientInfo>& clientInfo = aLoadInfo->GetClientInfo();
462 if (clientInfo.isSome()) {
463 ipcClientInfo.emplace(clientInfo.ref().ToIPC());
464 }
465
466 Maybe<IPCClientInfo> ipcReservedClientInfo;
467 const Maybe<ClientInfo>& reservedClientInfo =
468 aLoadInfo->GetReservedClientInfo();
469 if (reservedClientInfo.isSome()) {
470 ipcReservedClientInfo.emplace(reservedClientInfo.ref().ToIPC());
471 }
472
473 Maybe<IPCClientInfo> ipcInitialClientInfo;
474 const Maybe<ClientInfo>& initialClientInfo =
475 aLoadInfo->GetInitialClientInfo();
476 if (initialClientInfo.isSome()) {
477 ipcInitialClientInfo.emplace(initialClientInfo.ref().ToIPC());
478 }
479
480 Maybe<IPCServiceWorkerDescriptor> ipcController;
481 const Maybe<ServiceWorkerDescriptor>& controller = aLoadInfo->GetController();
482 if (controller.isSome()) {
483 ipcController.emplace(controller.ref().ToIPC());
484 }
485
486 nsAutoString cspNonce;
487 Unused << NS_WARN_IF(NS_FAILED(aLoadInfo->GetCspNonce(cspNonce)))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(aLoadInfo
->GetCspNonce(cspNonce))), 0))), "NS_FAILED(aLoadInfo->GetCspNonce(cspNonce))"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 487)
;
488
489 nsAutoString integrityMetadata;
490 Unused << NS_WARN_IF(NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(aLoadInfo
->GetIntegrityMetadata(integrityMetadata))), 0))), "NS_FAILED(aLoadInfo->GetIntegrityMetadata(integrityMetadata))"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 491)
491 NS_FAILED(aLoadInfo->GetIntegrityMetadata(integrityMetadata)))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(aLoadInfo
->GetIntegrityMetadata(integrityMetadata))), 0))), "NS_FAILED(aLoadInfo->GetIntegrityMetadata(integrityMetadata))"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 491)
;
492
493 nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
494 rv = aLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings));
495 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 495); return rv; } } while (false)
;
496
497 CookieJarSettingsArgs cookieJarSettingsArgs;
498 static_cast<CookieJarSettings*>(cookieJarSettings.get())
499 ->Serialize(cookieJarSettingsArgs);
500
501 Maybe<CSPInfo> maybeCspToInheritInfo;
502 nsCOMPtr<nsIContentSecurityPolicy> cspToInherit =
503 aLoadInfo->GetCspToInherit();
504 if (cspToInherit) {
505 CSPInfo cspToInheritInfo;
506 Unused << NS_WARN_IF(NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(CSPToCSPInfo
(cspToInherit, &cspToInheritInfo))), 0))), "NS_FAILED(CSPToCSPInfo(cspToInherit, &cspToInheritInfo))"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 507)
507 NS_FAILED(CSPToCSPInfo(cspToInherit, &cspToInheritInfo)))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(CSPToCSPInfo
(cspToInherit, &cspToInheritInfo))), 0))), "NS_FAILED(CSPToCSPInfo(cspToInherit, &cspToInheritInfo))"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 507)
;
508 maybeCspToInheritInfo.emplace(cspToInheritInfo);
509 }
510
511 nsCOMPtr<nsIURI> unstrippedURI;
512 Unused << aLoadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI));
513
514 Maybe<bool> isThirdPartyContextToTopWindow;
515 if (static_cast<LoadInfo*>(aLoadInfo)
516 ->HasIsThirdPartyContextToTopWindowSet()) {
517 isThirdPartyContextToTopWindow.emplace(
518 aLoadInfo->GetIsThirdPartyContextToTopWindow());
519 }
520
521 Maybe<InterceptionInfoArg> interceptionInfoArg;
522 nsIInterceptionInfo* interceptionInfo = aLoadInfo->InterceptionInfo();
523 if (interceptionInfo) {
524 Maybe<PrincipalInfo> triggeringPrincipalInfo;
525 if (interceptionInfo->TriggeringPrincipal()) {
526 triggeringPrincipalInfo.emplace();
527 rv = PrincipalToPrincipalInfo(interceptionInfo->TriggeringPrincipal(),
Value stored to 'rv' is never read
528 triggeringPrincipalInfo.ptr());
529 }
530
531 nsTArray<RedirectHistoryEntryInfo> redirectChain;
532 for (const nsCOMPtr<nsIRedirectHistoryEntry>& redirectEntry :
533 interceptionInfo->RedirectChain()) {
534 RedirectHistoryEntryInfo* entry = redirectChain.AppendElement();
535 rv = RHEntryToRHEntryInfo(redirectEntry, entry);
536 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 536); return rv; } } while (false)
;
537 }
538
539 interceptionInfoArg = Some(InterceptionInfoArg(
540 triggeringPrincipalInfo, interceptionInfo->ContentPolicyType(),
541 redirectChain, interceptionInfo->FromThirdParty()));
542 }
543
544 Maybe<uint64_t> overriddenFingerprintingSettingsArg;
545 Maybe<RFPTarget> overriddenFingerprintingSettings =
546 aLoadInfo->GetOverriddenFingerprintingSettings();
547
548 if (overriddenFingerprintingSettings) {
549 overriddenFingerprintingSettingsArg =
550 Some(uint64_t(overriddenFingerprintingSettings.ref()));
551 }
552
553 *outLoadInfoArgs = LoadInfoArgs(
554 loadingPrincipalInfo, triggeringPrincipalInfo, principalToInheritInfo,
555 topLevelPrincipalInfo, optionalResultPrincipalURI, triggeringRemoteType,
556 aLoadInfo->GetSandboxedNullPrincipalID(), aLoadInfo->GetSecurityFlags(),
557 aLoadInfo->GetSandboxFlags(), aLoadInfo->GetTriggeringSandboxFlags(),
558 aLoadInfo->GetTriggeringWindowId(),
559 aLoadInfo->GetTriggeringStorageAccess(),
560 aLoadInfo->InternalContentPolicyType(),
561 static_cast<uint32_t>(aLoadInfo->GetTainting()),
562 aLoadInfo->GetBlockAllMixedContent(),
563 aLoadInfo->GetUpgradeInsecureRequests(),
564 aLoadInfo->GetBrowserUpgradeInsecureRequests(),
565 aLoadInfo->GetBrowserDidUpgradeInsecureRequests(),
566 aLoadInfo->GetBrowserWouldUpgradeInsecureRequests(),
567 aLoadInfo->GetForceAllowDataURI(),
568 aLoadInfo->GetAllowInsecureRedirectToDataURI(),
569 aLoadInfo->GetSkipContentPolicyCheckForWebRequest(),
570 aLoadInfo->GetOriginalFrameSrcLoad(),
571 aLoadInfo->GetForceInheritPrincipalDropped(),
572 aLoadInfo->GetInnerWindowID(), aLoadInfo->GetBrowsingContextID(),
573 aLoadInfo->GetFrameBrowsingContextID(),
574 aLoadInfo->GetInitialSecurityCheckDone(),
575 aLoadInfo->GetIsInThirdPartyContext(), isThirdPartyContextToTopWindow,
576 aLoadInfo->GetIsFormSubmission(), aLoadInfo->GetSendCSPViolationEvents(),
577 aLoadInfo->GetOriginAttributes(), redirectChainIncludingInternalRedirects,
578 redirectChain, aLoadInfo->GetHasInjectedCookieForCookieBannerHandling(),
579 aLoadInfo->GetWasSchemelessInput(), ipcClientInfo, ipcReservedClientInfo,
580 ipcInitialClientInfo, ipcController, aLoadInfo->CorsUnsafeHeaders(),
581 aLoadInfo->GetForcePreflight(), aLoadInfo->GetIsPreflight(),
582 aLoadInfo->GetLoadTriggeredFromExternal(),
583 aLoadInfo->GetServiceWorkerTaintingSynthesized(),
584 aLoadInfo->GetDocumentHasUserInteracted(),
585 aLoadInfo->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(),
586 aLoadInfo->GetNeedForCheckingAntiTrackingHeuristic(), cspNonce,
587 integrityMetadata, aLoadInfo->GetSkipContentSniffing(),
588 aLoadInfo->GetHttpsOnlyStatus(), aLoadInfo->GetHstsStatus(),
589 aLoadInfo->GetHasValidUserGestureActivation(),
590 aLoadInfo->GetAllowDeprecatedSystemRequests(),
591 aLoadInfo->GetIsInDevToolsContext(), aLoadInfo->GetParserCreatedScript(),
592 aLoadInfo->GetIsFromProcessingFrameAttributes(),
593 aLoadInfo->GetIsMediaRequest(), aLoadInfo->GetIsMediaInitialRequest(),
594 aLoadInfo->GetIsFromObjectOrEmbed(), cookieJarSettingsArgs,
595 aLoadInfo->GetRequestBlockingReason(), maybeCspToInheritInfo,
596 aLoadInfo->GetStoragePermission(), overriddenFingerprintingSettingsArg,
597 aLoadInfo->GetIsMetaRefresh(), aLoadInfo->GetLoadingEmbedderPolicy(),
598 aLoadInfo->GetIsOriginTrialCoepCredentiallessEnabledForTopLevel(),
599 unstrippedURI, interceptionInfoArg);
600
601 return NS_OK;
602}
603
604nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& aLoadInfoArgs,
605 const nsACString& aOriginRemoteType,
606 nsILoadInfo** outLoadInfo) {
607 return LoadInfoArgsToLoadInfo(aLoadInfoArgs, aOriginRemoteType, nullptr,
608 outLoadInfo);
609}
610nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& aLoadInfoArgs,
611 const nsACString& aOriginRemoteType,
612 nsINode* aCspToInheritLoadingContext,
613 nsILoadInfo** outLoadInfo) {
614 RefPtr<LoadInfo> loadInfo;
615 nsresult rv = LoadInfoArgsToLoadInfo(aLoadInfoArgs, aOriginRemoteType,
616 aCspToInheritLoadingContext,
617 getter_AddRefs(loadInfo));
618 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 618); return rv; } } while (false)
;
619
620 loadInfo.forget(outLoadInfo);
621 return NS_OK;
622}
623
624nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& aLoadInfoArgs,
625 const nsACString& aOriginRemoteType,
626 LoadInfo** outLoadInfo) {
627 return LoadInfoArgsToLoadInfo(aLoadInfoArgs, aOriginRemoteType, nullptr,
628 outLoadInfo);
629}
630nsresult LoadInfoArgsToLoadInfo(const LoadInfoArgs& loadInfoArgs,
631 const nsACString& aOriginRemoteType,
632 nsINode* aCspToInheritLoadingContext,
633 LoadInfo** outLoadInfo) {
634 nsCOMPtr<nsIPrincipal> loadingPrincipal;
635 if (loadInfoArgs.requestingPrincipalInfo().isSome()) {
636 auto loadingPrincipalOrErr =
637 PrincipalInfoToPrincipal(loadInfoArgs.requestingPrincipalInfo().ref());
638 if (NS_WARN_IF(loadingPrincipalOrErr.isErr())NS_warn_if_impl(loadingPrincipalOrErr.isErr(), "loadingPrincipalOrErr.isErr()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 638)
) {
639 return loadingPrincipalOrErr.unwrapErr();
640 }
641 loadingPrincipal = loadingPrincipalOrErr.unwrap();
642 }
643
644 auto triggeringPrincipalOrErr =
645 PrincipalInfoToPrincipal(loadInfoArgs.triggeringPrincipalInfo());
646 if (NS_WARN_IF(triggeringPrincipalOrErr.isErr())NS_warn_if_impl(triggeringPrincipalOrErr.isErr(), "triggeringPrincipalOrErr.isErr()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 646)
) {
647 return triggeringPrincipalOrErr.unwrapErr();
648 }
649 nsCOMPtr<nsIPrincipal> triggeringPrincipal =
650 triggeringPrincipalOrErr.unwrap();
651
652 nsCOMPtr<nsIPrincipal> principalToInherit;
653 nsCOMPtr<nsIPrincipal> flattenedPrincipalToInherit;
654 if (loadInfoArgs.principalToInheritInfo().isSome()) {
655 auto principalToInheritOrErr =
656 PrincipalInfoToPrincipal(loadInfoArgs.principalToInheritInfo().ref());
657 if (NS_WARN_IF(principalToInheritOrErr.isErr())NS_warn_if_impl(principalToInheritOrErr.isErr(), "principalToInheritOrErr.isErr()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 657)
) {
658 return principalToInheritOrErr.unwrapErr();
659 }
660 flattenedPrincipalToInherit = principalToInheritOrErr.unwrap();
661 }
662
663 if (XRE_IsContentProcess()) {
664 auto targetBrowsingContextId = loadInfoArgs.frameBrowsingContextID()
665 ? loadInfoArgs.frameBrowsingContextID()
666 : loadInfoArgs.browsingContextID();
667 if (RefPtr<BrowsingContext> bc =
668 BrowsingContext::Get(targetBrowsingContextId)) {
669 auto [originalTriggeringPrincipal, originalPrincipalToInherit] =
670 bc->GetTriggeringAndInheritPrincipalsForCurrentLoad();
671
672 if (originalTriggeringPrincipal &&
673 originalTriggeringPrincipal->Equals(triggeringPrincipal)) {
674 triggeringPrincipal = originalTriggeringPrincipal;
675 }
676 if (originalPrincipalToInherit &&
677 (loadInfoArgs.securityFlags() &
678 nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL) &&
679 originalPrincipalToInherit->Equals(flattenedPrincipalToInherit)) {
680 principalToInherit = originalPrincipalToInherit;
681 }
682 }
683 }
684 if (!principalToInherit && loadInfoArgs.principalToInheritInfo().isSome()) {
685 principalToInherit = flattenedPrincipalToInherit;
686 }
687
688 nsCOMPtr<nsIPrincipal> topLevelPrincipal;
689 if (loadInfoArgs.topLevelPrincipalInfo().isSome()) {
690 auto topLevelPrincipalOrErr =
691 PrincipalInfoToPrincipal(loadInfoArgs.topLevelPrincipalInfo().ref());
692 if (NS_WARN_IF(topLevelPrincipalOrErr.isErr())NS_warn_if_impl(topLevelPrincipalOrErr.isErr(), "topLevelPrincipalOrErr.isErr()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 692)
) {
693 return topLevelPrincipalOrErr.unwrapErr();
694 }
695 topLevelPrincipal = topLevelPrincipalOrErr.unwrap();
696 }
697
698 nsCOMPtr<nsIURI> resultPrincipalURI;
699 if (loadInfoArgs.resultPrincipalURI().isSome()) {
700 resultPrincipalURI = DeserializeURI(loadInfoArgs.resultPrincipalURI());
701 NS_ENSURE_TRUE(resultPrincipalURI, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(resultPrincipalURI)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "resultPrincipalURI" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 701); return NS_ERROR_UNEXPECTED; } } while (false)
;
702 }
703
704 // If we received this message from a content process, reset
705 // triggeringRemoteType to the process which sent us the message. If the
706 // parent sent us the message, we trust it to provide the correct triggering
707 // remote type.
708 //
709 // This means that the triggering remote type will be reset if a LoadInfo is
710 // bounced through a content process, as the LoadInfo can no longer be
711 // validated to be coming from the originally specified remote type.
712 nsCString triggeringRemoteType = loadInfoArgs.triggeringRemoteType();
713 if (aOriginRemoteType != NOT_REMOTE_TYPEVoidCString() &&
714 aOriginRemoteType != triggeringRemoteType) {
715 triggeringRemoteType = aOriginRemoteType;
716 }
717
718 RedirectHistoryArray redirectChainIncludingInternalRedirects;
719 for (const RedirectHistoryEntryInfo& entryInfo :
720 loadInfoArgs.redirectChainIncludingInternalRedirects()) {
721 nsCOMPtr<nsIRedirectHistoryEntry> redirectHistoryEntry =
722 RHEntryInfoToRHEntry(entryInfo);
723 NS_ENSURE_TRUE(redirectHistoryEntry, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(redirectHistoryEntry)), 0))) {
NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "redirectHistoryEntry"
") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 723); return NS_ERROR_UNEXPECTED; } } while (false)
;
724 redirectChainIncludingInternalRedirects.AppendElement(
725 redirectHistoryEntry.forget());
726 }
727
728 RedirectHistoryArray redirectChain;
729 for (const RedirectHistoryEntryInfo& entryInfo :
730 loadInfoArgs.redirectChain()) {
731 nsCOMPtr<nsIRedirectHistoryEntry> redirectHistoryEntry =
732 RHEntryInfoToRHEntry(entryInfo);
733 NS_ENSURE_TRUE(redirectHistoryEntry, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(redirectHistoryEntry)), 0))) {
NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "redirectHistoryEntry"
") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 733); return NS_ERROR_UNEXPECTED; } } while (false)
;
734 redirectChain.AppendElement(redirectHistoryEntry.forget());
735 }
736 nsTArray<nsCOMPtr<nsIPrincipal>> ancestorPrincipals;
737 nsTArray<uint64_t> ancestorBrowsingContextIDs;
738 if (XRE_IsParentProcess() &&
739 (nsContentUtils::InternalContentPolicyTypeToExternal(
740 loadInfoArgs.contentPolicyType()) !=
741 ExtContentPolicy::TYPE_DOCUMENT)) {
742 // Only fill out ancestor principals and browsing context IDs when we
743 // are deserializing LoadInfoArgs to be LoadInfo for a subresource
744 RefPtr<BrowsingContext> parentBC =
745 BrowsingContext::Get(loadInfoArgs.browsingContextID());
746 if (parentBC) {
747 LoadInfo::ComputeAncestors(parentBC->Canonical(), ancestorPrincipals,
748 ancestorBrowsingContextIDs);
749 }
750 }
751
752 Maybe<ClientInfo> clientInfo;
753 if (loadInfoArgs.clientInfo().isSome()) {
754 clientInfo.emplace(ClientInfo(loadInfoArgs.clientInfo().ref()));
755 }
756
757 Maybe<ClientInfo> reservedClientInfo;
758 if (loadInfoArgs.reservedClientInfo().isSome()) {
759 reservedClientInfo.emplace(
760 ClientInfo(loadInfoArgs.reservedClientInfo().ref()));
761 }
762
763 Maybe<ClientInfo> initialClientInfo;
764 if (loadInfoArgs.initialClientInfo().isSome()) {
765 initialClientInfo.emplace(
766 ClientInfo(loadInfoArgs.initialClientInfo().ref()));
767 }
768
769 // We can have an initial client info or a reserved client info, but not both.
770 MOZ_DIAGNOSTIC_ASSERT(reservedClientInfo.isNothing() ||do { static_assert( mozilla::detail::AssertionConditionType<
decltype(reservedClientInfo.isNothing() || initialClientInfo.
isNothing())>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(reservedClientInfo.isNothing() ||
initialClientInfo.isNothing()))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("reservedClientInfo.isNothing() || initialClientInfo.isNothing()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 771); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "reservedClientInfo.isNothing() || initialClientInfo.isNothing()"
")"); do { *((volatile int*)__null) = 771; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
771 initialClientInfo.isNothing())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(reservedClientInfo.isNothing() || initialClientInfo.
isNothing())>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(reservedClientInfo.isNothing() ||
initialClientInfo.isNothing()))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("reservedClientInfo.isNothing() || initialClientInfo.isNothing()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 771); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "reservedClientInfo.isNothing() || initialClientInfo.isNothing()"
")"); do { *((volatile int*)__null) = 771; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
772 NS_ENSURE_TRUE(do { if ((__builtin_expect(!!(!(reservedClientInfo.isNothing(
) || initialClientInfo.isNothing())), 0))) { NS_DebugBreak(NS_DEBUG_WARNING
, "NS_ENSURE_TRUE(" "reservedClientInfo.isNothing() || initialClientInfo.isNothing()"
") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 774); return NS_ERROR_UNEXPECTED; } } while (false)
773 reservedClientInfo.isNothing() || initialClientInfo.isNothing(),do { if ((__builtin_expect(!!(!(reservedClientInfo.isNothing(
) || initialClientInfo.isNothing())), 0))) { NS_DebugBreak(NS_DEBUG_WARNING
, "NS_ENSURE_TRUE(" "reservedClientInfo.isNothing() || initialClientInfo.isNothing()"
") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 774); return NS_ERROR_UNEXPECTED; } } while (false)
774 NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(reservedClientInfo.isNothing(
) || initialClientInfo.isNothing())), 0))) { NS_DebugBreak(NS_DEBUG_WARNING
, "NS_ENSURE_TRUE(" "reservedClientInfo.isNothing() || initialClientInfo.isNothing()"
") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 774); return NS_ERROR_UNEXPECTED; } } while (false)
;
775
776 Maybe<ServiceWorkerDescriptor> controller;
777 if (loadInfoArgs.controller().isSome()) {
778 controller.emplace(
779 ServiceWorkerDescriptor(loadInfoArgs.controller().ref()));
780 }
781
782 nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
783 CookieJarSettings::Deserialize(loadInfoArgs.cookieJarSettings(),
784 getter_AddRefs(cookieJarSettings));
785
786 Maybe<RFPTarget> overriddenFingerprintingSettings;
787 if (loadInfoArgs.overriddenFingerprintingSettings().isSome()) {
788 overriddenFingerprintingSettings.emplace(
789 RFPTarget(loadInfoArgs.overriddenFingerprintingSettings().ref()));
790 }
791
792 nsCOMPtr<nsIContentSecurityPolicy> cspToInherit;
793 Maybe<mozilla::ipc::CSPInfo> cspToInheritInfo =
794 loadInfoArgs.cspToInheritInfo();
795 if (cspToInheritInfo.isSome()) {
796 nsCOMPtr<Document> doc = do_QueryInterface(aCspToInheritLoadingContext);
797 cspToInherit = CSPInfoToCSP(cspToInheritInfo.ref(), doc);
798 }
799
800 // Restore the loadingContext for frames using the BrowsingContext's
801 // embedder element. Note that this only works if the embedder is
802 // same-process, so won't be fission compatible.
803 nsCOMPtr<nsINode> loadingContext;
804 RefPtr<BrowsingContext> frameBrowsingContext =
805 BrowsingContext::Get(loadInfoArgs.frameBrowsingContextID());
806 if (frameBrowsingContext) {
807 loadingContext = frameBrowsingContext->GetEmbedderElement();
808 }
809
810 Maybe<bool> isThirdPartyContextToTopWindow;
811 if (loadInfoArgs.isThirdPartyContextToTopWindow().isSome()) {
812 isThirdPartyContextToTopWindow.emplace(
813 loadInfoArgs.isThirdPartyContextToTopWindow().ref());
814 }
815
816 nsCOMPtr<nsIInterceptionInfo> interceptionInfo;
817 if (loadInfoArgs.interceptionInfo().isSome()) {
818 const InterceptionInfoArg& interceptionInfoArg =
819 loadInfoArgs.interceptionInfo().ref();
820 nsCOMPtr<nsIPrincipal> triggeringPrincipal;
821 if (interceptionInfoArg.triggeringPrincipalInfo().isSome()) {
822 auto triggeringPrincipalOrErr = PrincipalInfoToPrincipal(
823 interceptionInfoArg.triggeringPrincipalInfo().ref());
824 if (NS_WARN_IF(triggeringPrincipalOrErr.isErr())NS_warn_if_impl(triggeringPrincipalOrErr.isErr(), "triggeringPrincipalOrErr.isErr()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 824)
) {
825 return triggeringPrincipalOrErr.unwrapErr();
826 }
827 triggeringPrincipal = triggeringPrincipalOrErr.unwrap();
828 }
829
830 RedirectHistoryArray redirectChain;
831 for (const RedirectHistoryEntryInfo& entryInfo :
832 interceptionInfoArg.redirectChain()) {
833 nsCOMPtr<nsIRedirectHistoryEntry> redirectHistoryEntry =
834 RHEntryInfoToRHEntry(entryInfo);
835 NS_ENSURE_TRUE(redirectHistoryEntry, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(redirectHistoryEntry)), 0))) {
NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "redirectHistoryEntry"
") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 835); return NS_ERROR_UNEXPECTED; } } while (false)
;
836 redirectChain.AppendElement(redirectHistoryEntry.forget());
837 }
838
839 interceptionInfo = new InterceptionInfo(
840 triggeringPrincipal, interceptionInfoArg.contentPolicyType(),
841 redirectChain, interceptionInfoArg.fromThirdParty());
842 }
843
844 RefPtr<mozilla::net::LoadInfo> loadInfo = new mozilla::net::LoadInfo(
845 loadingPrincipal, triggeringPrincipal, principalToInherit,
846 topLevelPrincipal, resultPrincipalURI, cookieJarSettings, cspToInherit,
847 triggeringRemoteType, loadInfoArgs.sandboxedNullPrincipalID(), clientInfo,
848 reservedClientInfo, initialClientInfo, controller,
849 loadInfoArgs.securityFlags(), loadInfoArgs.sandboxFlags(),
850 loadInfoArgs.triggeringSandboxFlags(), loadInfoArgs.triggeringWindowId(),
851 loadInfoArgs.triggeringStorageAccess(), loadInfoArgs.contentPolicyType(),
852 static_cast<LoadTainting>(loadInfoArgs.tainting()),
853 loadInfoArgs.blockAllMixedContent(),
854 loadInfoArgs.upgradeInsecureRequests(),
855 loadInfoArgs.browserUpgradeInsecureRequests(),
856 loadInfoArgs.browserDidUpgradeInsecureRequests(),
857 loadInfoArgs.browserWouldUpgradeInsecureRequests(),
858 loadInfoArgs.forceAllowDataURI(),
859 loadInfoArgs.allowInsecureRedirectToDataURI(),
860 loadInfoArgs.skipContentPolicyCheckForWebRequest(),
861 loadInfoArgs.originalFrameSrcLoad(),
862 loadInfoArgs.forceInheritPrincipalDropped(), loadInfoArgs.innerWindowID(),
863 loadInfoArgs.browsingContextID(), loadInfoArgs.frameBrowsingContextID(),
864 loadInfoArgs.initialSecurityCheckDone(),
865 loadInfoArgs.isInThirdPartyContext(), isThirdPartyContextToTopWindow,
866 loadInfoArgs.isFormSubmission(), loadInfoArgs.sendCSPViolationEvents(),
867 loadInfoArgs.originAttributes(),
868 std::move(redirectChainIncludingInternalRedirects),
869 std::move(redirectChain), std::move(ancestorPrincipals),
870 ancestorBrowsingContextIDs, loadInfoArgs.corsUnsafeHeaders(),
871 loadInfoArgs.forcePreflight(), loadInfoArgs.isPreflight(),
872 loadInfoArgs.loadTriggeredFromExternal(),
873 loadInfoArgs.serviceWorkerTaintingSynthesized(),
874 loadInfoArgs.documentHasUserInteracted(),
875 loadInfoArgs.allowListFutureDocumentsCreatedFromThisRedirectChain(),
876 loadInfoArgs.needForCheckingAntiTrackingHeuristic(),
877 loadInfoArgs.cspNonce(), loadInfoArgs.integrityMetadata(),
878 loadInfoArgs.skipContentSniffing(), loadInfoArgs.httpsOnlyStatus(),
879 loadInfoArgs.hstsStatus(), loadInfoArgs.hasValidUserGestureActivation(),
880 loadInfoArgs.allowDeprecatedSystemRequests(),
881 loadInfoArgs.isInDevToolsContext(), loadInfoArgs.parserCreatedScript(),
882 loadInfoArgs.storagePermission(), overriddenFingerprintingSettings,
883 loadInfoArgs.isMetaRefresh(), loadInfoArgs.requestBlockingReason(),
884 loadingContext, loadInfoArgs.loadingEmbedderPolicy(),
885 loadInfoArgs.originTrialCoepCredentiallessEnabledForTopLevel(),
886 loadInfoArgs.unstrippedURI(), interceptionInfo,
887 loadInfoArgs.hasInjectedCookieForCookieBannerHandling(),
888 loadInfoArgs.wasSchemelessInput());
889
890 if (loadInfoArgs.isFromProcessingFrameAttributes()) {
891 loadInfo->SetIsFromProcessingFrameAttributes();
892 }
893
894 if (loadInfoArgs.isMediaRequest()) {
895 loadInfo->SetIsMediaRequest(true);
896
897 if (loadInfoArgs.isMediaInitialRequest()) {
898 loadInfo->SetIsMediaInitialRequest(true);
899 }
900 }
901
902 if (loadInfoArgs.isFromObjectOrEmbed()) {
903 loadInfo->SetIsFromObjectOrEmbed(true);
904 }
905
906 loadInfo.forget(outLoadInfo);
907 return NS_OK;
908}
909
910void LoadInfoToParentLoadInfoForwarder(
911 nsILoadInfo* aLoadInfo, ParentLoadInfoForwarderArgs* aForwarderArgsOut) {
912 Maybe<IPCServiceWorkerDescriptor> ipcController;
913 Maybe<ServiceWorkerDescriptor> controller(aLoadInfo->GetController());
914 if (controller.isSome()) {
915 ipcController.emplace(controller.ref().ToIPC());
916 }
917
918 uint32_t tainting = nsILoadInfo::TAINTING_BASIC;
919 Unused << aLoadInfo->GetTainting(&tainting);
920
921 Maybe<CookieJarSettingsArgs> cookieJarSettingsArgs;
922
923 nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
924 nsresult rv =
925 aLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings));
926 CookieJarSettings* cs =
927 static_cast<CookieJarSettings*>(cookieJarSettings.get());
928 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && cookieJarSettings && cs->HasBeenChanged()) {
929 CookieJarSettingsArgs args;
930 cs->Serialize(args);
931 cookieJarSettingsArgs = Some(args);
932 }
933
934 nsCOMPtr<nsIURI> unstrippedURI;
935 Unused << aLoadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI));
936
937 Maybe<bool> isThirdPartyContextToTopWindow;
938 if (static_cast<LoadInfo*>(aLoadInfo)
939 ->HasIsThirdPartyContextToTopWindowSet()) {
940 isThirdPartyContextToTopWindow.emplace(
941 aLoadInfo->GetIsThirdPartyContextToTopWindow());
942 }
943
944 Maybe<uint64_t> overriddenFingerprintingSettingsArg;
945 Maybe<RFPTarget> overriddenFingerprintingSettings =
946 aLoadInfo->GetOverriddenFingerprintingSettings();
947
948 if (overriddenFingerprintingSettings) {
949 overriddenFingerprintingSettingsArg =
950 Some(uint64_t(overriddenFingerprintingSettings.ref()));
951 }
952
953 *aForwarderArgsOut = ParentLoadInfoForwarderArgs(
954 aLoadInfo->GetAllowInsecureRedirectToDataURI(), ipcController, tainting,
955 aLoadInfo->GetSkipContentSniffing(), aLoadInfo->GetHttpsOnlyStatus(),
956 aLoadInfo->GetHstsStatus(), aLoadInfo->GetHasValidUserGestureActivation(),
957 aLoadInfo->GetAllowDeprecatedSystemRequests(),
958 aLoadInfo->GetIsInDevToolsContext(), aLoadInfo->GetParserCreatedScript(),
959 aLoadInfo->GetTriggeringSandboxFlags(),
960 aLoadInfo->GetTriggeringWindowId(),
961 aLoadInfo->GetTriggeringStorageAccess(),
962 aLoadInfo->GetServiceWorkerTaintingSynthesized(),
963 aLoadInfo->GetDocumentHasUserInteracted(),
964 aLoadInfo->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(),
965 cookieJarSettingsArgs, aLoadInfo->GetRequestBlockingReason(),
966 aLoadInfo->GetStoragePermission(), overriddenFingerprintingSettingsArg,
967 aLoadInfo->GetIsMetaRefresh(), isThirdPartyContextToTopWindow,
968 aLoadInfo->GetIsInThirdPartyContext(), unstrippedURI);
969}
970
971nsresult MergeParentLoadInfoForwarder(
972 ParentLoadInfoForwarderArgs const& aForwarderArgs, nsILoadInfo* aLoadInfo) {
973 nsresult rv;
974
975 rv = aLoadInfo->SetAllowInsecureRedirectToDataURI(
976 aForwarderArgs.allowInsecureRedirectToDataURI());
977 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 977); return rv; } } while (false)
;
978
979 aLoadInfo->ClearController();
980 auto& controller = aForwarderArgs.controller();
981 if (controller.isSome()) {
982 aLoadInfo->SetController(ServiceWorkerDescriptor(controller.ref()));
983 }
984
985 if (aForwarderArgs.serviceWorkerTaintingSynthesized()) {
986 aLoadInfo->SynthesizeServiceWorkerTainting(
987 static_cast<LoadTainting>(aForwarderArgs.tainting()));
988 } else {
989 aLoadInfo->MaybeIncreaseTainting(aForwarderArgs.tainting());
990 }
991
992 rv = aLoadInfo->SetSkipContentSniffing(aForwarderArgs.skipContentSniffing());
993 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 993); return rv; } } while (false)
;
994
995 rv = aLoadInfo->SetHttpsOnlyStatus(aForwarderArgs.httpsOnlyStatus());
996 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 996); return rv; } } while (false)
;
997
998 rv = aLoadInfo->SetHstsStatus(aForwarderArgs.hstsStatus());
999 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 999); return rv; } } while (false)
;
1000
1001 rv = aLoadInfo->SetTriggeringSandboxFlags(
1002 aForwarderArgs.triggeringSandboxFlags());
1003 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1003); return rv; } } while (false)
;
1004
1005 rv = aLoadInfo->SetTriggeringWindowId(aForwarderArgs.triggeringWindowId());
1006 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1006); return rv; } } while (false)
;
1007
1008 rv = aLoadInfo->SetTriggeringStorageAccess(
1009 aForwarderArgs.triggeringStorageAccess());
1010 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1010); return rv; } } while (false)
;
1011
1012 rv = aLoadInfo->SetHasValidUserGestureActivation(
1013 aForwarderArgs.hasValidUserGestureActivation());
1014 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1014); return rv; } } while (false)
;
1015
1016 rv = aLoadInfo->SetAllowDeprecatedSystemRequests(
1017 aForwarderArgs.allowDeprecatedSystemRequests());
1018 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1018); return rv; } } while (false)
;
1019
1020 rv = aLoadInfo->SetIsInDevToolsContext(aForwarderArgs.isInDevToolsContext());
1021 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1021); return rv; } } while (false)
;
1022
1023 rv = aLoadInfo->SetParserCreatedScript(aForwarderArgs.parserCreatedScript());
1024 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1024); return rv; } } while (false)
;
1025
1026 MOZ_ALWAYS_SUCCEEDS(aLoadInfo->SetDocumentHasUserInteracted(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aLoadInfo->SetDocumentHasUserInteracted( aForwarderArgs.documentHasUserInteracted
()))), 1)))), 1))) { } else { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(aLoadInfo->SetDocumentHasUserInteracted( aForwarderArgs.documentHasUserInteracted()))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1027); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(aLoadInfo->SetDocumentHasUserInteracted( aForwarderArgs.documentHasUserInteracted()))"
")"); do { *((volatile int*)__null) = 1027; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
1027 aForwarderArgs.documentHasUserInteracted()))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aLoadInfo->SetDocumentHasUserInteracted( aForwarderArgs.documentHasUserInteracted
()))), 1)))), 1))) { } else { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(aLoadInfo->SetDocumentHasUserInteracted( aForwarderArgs.documentHasUserInteracted()))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1027); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(aLoadInfo->SetDocumentHasUserInteracted( aForwarderArgs.documentHasUserInteracted()))"
")"); do { *((volatile int*)__null) = 1027; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
1028 MOZ_ALWAYS_SUCCEEDS(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain
( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain
()))), 1)))), 1))) { } else { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain()))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1031); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain()))"
")"); do { *((volatile int*)__null) = 1031; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
1029 aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain
( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain
()))), 1)))), 1))) { } else { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain()))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1031); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain()))"
")"); do { *((volatile int*)__null) = 1031; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
1030 aForwarderArgsdo { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain
( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain
()))), 1)))), 1))) { } else { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain()))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1031); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain()))"
")"); do { *((volatile int*)__null) = 1031; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
1031 .allowListFutureDocumentsCreatedFromThisRedirectChain()))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain
( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain
()))), 1)))), 1))) { } else { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain()))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1031); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(aLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( aForwarderArgs .allowListFutureDocumentsCreatedFromThisRedirectChain()))"
")"); do { *((volatile int*)__null) = 1031; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
1032 MOZ_ALWAYS_SUCCEEDS(aLoadInfo->SetRequestBlockingReason(do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aLoadInfo->SetRequestBlockingReason( aForwarderArgs.requestBlockingReason
()))), 1)))), 1))) { } else { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(aLoadInfo->SetRequestBlockingReason( aForwarderArgs.requestBlockingReason()))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1033); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(aLoadInfo->SetRequestBlockingReason( aForwarderArgs.requestBlockingReason()))"
")"); do { *((volatile int*)__null) = 1033; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
1033 aForwarderArgs.requestBlockingReason()))do { if ((__builtin_expect(!!(((bool)(__builtin_expect(!!(!NS_FAILED_impl
(aLoadInfo->SetRequestBlockingReason( aForwarderArgs.requestBlockingReason
()))), 1)))), 1))) { } else { do { static_assert( mozilla::detail
::AssertionConditionType<decltype(false)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("false" " (" "NS_SUCCEEDED(aLoadInfo->SetRequestBlockingReason( aForwarderArgs.requestBlockingReason()))"
")", "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1033); AnnotateMozCrashReason("MOZ_DIAGNOSTIC_ASSERT" "(" "false"
") (" "NS_SUCCEEDED(aLoadInfo->SetRequestBlockingReason( aForwarderArgs.requestBlockingReason()))"
")"); do { *((volatile int*)__null) = 1033; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
1034
1035 const Maybe<CookieJarSettingsArgs>& cookieJarSettingsArgs =
1036 aForwarderArgs.cookieJarSettings();
1037 if (cookieJarSettingsArgs.isSome()) {
1038 nsCOMPtr<nsICookieJarSettings> cookieJarSettings;
1039 nsresult rv =
1040 aLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings));
1041 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && cookieJarSettings) {
1042 static_cast<CookieJarSettings*>(cookieJarSettings.get())
1043 ->Merge(cookieJarSettingsArgs.ref());
1044 }
1045 }
1046
1047 rv = aLoadInfo->SetStoragePermission(aForwarderArgs.storagePermission());
1048 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1048); return rv; } } while (false)
;
1049
1050 rv = aLoadInfo->SetIsMetaRefresh(aForwarderArgs.isMetaRefresh());
1051 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1051); return rv; } } while (false)
;
1052
1053 const Maybe<uint64_t> overriddenFingerprintingSettings =
1054 aForwarderArgs.overriddenFingerprintingSettings();
1055 if (overriddenFingerprintingSettings.isSome()) {
1056 aLoadInfo->SetOverriddenFingerprintingSettings(
1057 RFPTarget(overriddenFingerprintingSettings.ref()));
1058 }
1059
1060 static_cast<LoadInfo*>(aLoadInfo)->ClearIsThirdPartyContextToTopWindow();
1061 if (aForwarderArgs.isThirdPartyContextToTopWindow().isSome()) {
1062 rv = aLoadInfo->SetIsThirdPartyContextToTopWindow(
1063 aForwarderArgs.isThirdPartyContextToTopWindow().ref());
1064 }
1065 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1065); return rv; } } while (false)
;
1066
1067 rv = aLoadInfo->SetIsInThirdPartyContext(
1068 aForwarderArgs.isInThirdPartyContext());
1069 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1069); return rv; } } while (false)
;
1070
1071 rv = aLoadInfo->SetUnstrippedURI(aForwarderArgs.unstrippedURI());
1072 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, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1072); return rv; } } while (false)
;
1073
1074 return NS_OK;
1075}
1076
1077void LoadInfoToChildLoadInfoForwarder(
1078 nsILoadInfo* aLoadInfo, ChildLoadInfoForwarderArgs* aForwarderArgsOut) {
1079 Maybe<IPCClientInfo> ipcReserved;
1080 Maybe<ClientInfo> reserved(aLoadInfo->GetReservedClientInfo());
1081 if (reserved.isSome()) {
1082 ipcReserved.emplace(reserved.ref().ToIPC());
1083 }
1084
1085 Maybe<IPCClientInfo> ipcInitial;
1086 Maybe<ClientInfo> initial(aLoadInfo->GetInitialClientInfo());
1087 if (initial.isSome()) {
1088 ipcInitial.emplace(initial.ref().ToIPC());
1089 }
1090
1091 Maybe<IPCServiceWorkerDescriptor> ipcController;
1092 Maybe<ServiceWorkerDescriptor> controller(aLoadInfo->GetController());
1093 if (controller.isSome()) {
1094 ipcController.emplace(controller.ref().ToIPC());
1095 }
1096
1097 *aForwarderArgsOut =
1098 ChildLoadInfoForwarderArgs(ipcReserved, ipcInitial, ipcController,
1099 aLoadInfo->GetRequestBlockingReason());
1100}
1101
1102nsresult MergeChildLoadInfoForwarder(
1103 const ChildLoadInfoForwarderArgs& aForwarderArgs, nsILoadInfo* aLoadInfo) {
1104 Maybe<ClientInfo> reservedClientInfo;
1105 auto& ipcReserved = aForwarderArgs.reservedClientInfo();
1106 if (ipcReserved.isSome()) {
1107 reservedClientInfo.emplace(ClientInfo(ipcReserved.ref()));
1108 }
1109
1110 Maybe<ClientInfo> initialClientInfo;
1111 auto& ipcInitial = aForwarderArgs.initialClientInfo();
1112 if (ipcInitial.isSome()) {
1113 initialClientInfo.emplace(ClientInfo(ipcInitial.ref()));
1114 }
1115
1116 // There should only be at most one reserved or initial ClientInfo.
1117 if (NS_WARN_IF(reservedClientInfo.isSome() && initialClientInfo.isSome())NS_warn_if_impl(reservedClientInfo.isSome() && initialClientInfo
.isSome(), "reservedClientInfo.isSome() && initialClientInfo.isSome()"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1117)
) {
1118 return NS_ERROR_FAILURE;
1119 }
1120
1121 // If we received no reserved or initial ClientInfo, then we must not
1122 // already have one set. There are no use cases where this should
1123 // happen and we don't have a way to clear the current value.
1124 if (NS_WARN_IF(reservedClientInfo.isNothing() &&NS_warn_if_impl(reservedClientInfo.isNothing() && initialClientInfo
.isNothing() && (aLoadInfo->GetReservedClientInfo(
).isSome() || aLoadInfo->GetInitialClientInfo().isSome()),
"reservedClientInfo.isNothing() && initialClientInfo.isNothing() && (aLoadInfo->GetReservedClientInfo().isSome() || aLoadInfo->GetInitialClientInfo().isSome())"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1127)
1125 initialClientInfo.isNothing() &&NS_warn_if_impl(reservedClientInfo.isNothing() && initialClientInfo
.isNothing() && (aLoadInfo->GetReservedClientInfo(
).isSome() || aLoadInfo->GetInitialClientInfo().isSome()),
"reservedClientInfo.isNothing() && initialClientInfo.isNothing() && (aLoadInfo->GetReservedClientInfo().isSome() || aLoadInfo->GetInitialClientInfo().isSome())"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1127)
1126 (aLoadInfo->GetReservedClientInfo().isSome() ||NS_warn_if_impl(reservedClientInfo.isNothing() && initialClientInfo
.isNothing() && (aLoadInfo->GetReservedClientInfo(
).isSome() || aLoadInfo->GetInitialClientInfo().isSome()),
"reservedClientInfo.isNothing() && initialClientInfo.isNothing() && (aLoadInfo->GetReservedClientInfo().isSome() || aLoadInfo->GetInitialClientInfo().isSome())"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1127)
1127 aLoadInfo->GetInitialClientInfo().isSome()))NS_warn_if_impl(reservedClientInfo.isNothing() && initialClientInfo
.isNothing() && (aLoadInfo->GetReservedClientInfo(
).isSome() || aLoadInfo->GetInitialClientInfo().isSome()),
"reservedClientInfo.isNothing() && initialClientInfo.isNothing() && (aLoadInfo->GetReservedClientInfo().isSome() || aLoadInfo->GetInitialClientInfo().isSome())"
, "/var/lib/jenkins/workspace/firefox-scan-build/ipc/glue/BackgroundUtils.cpp"
, 1127)
) {
1128 return NS_ERROR_FAILURE;
1129 }
1130
1131 if (reservedClientInfo.isSome()) {
1132 // We need to override here instead of simply set the value. This
1133 // allows us to change the reserved client. This is necessary when
1134 // the ClientChannelHelper created a new reserved client in the
1135 // child-side of the redirect.
1136 aLoadInfo->OverrideReservedClientInfoInParent(reservedClientInfo.ref());
1137 } else if (initialClientInfo.isSome()) {
1138 aLoadInfo->SetInitialClientInfo(initialClientInfo.ref());
1139 }
1140
1141 aLoadInfo->ClearController();
1142 auto& controller = aForwarderArgs.controller();
1143 if (controller.isSome()) {
1144 aLoadInfo->SetController(ServiceWorkerDescriptor(controller.ref()));
1145 }
1146
1147 uint32_t blockingReason = aForwarderArgs.requestBlockingReason();
1148 if (blockingReason) {
1149 // We only want to override when non-null, so that any earlier set non-null
1150 // value is not reverted to 0.
1151 aLoadInfo->SetRequestBlockingReason(blockingReason);
1152 }
1153
1154 return NS_OK;
1155}
1156
1157} // namespace ipc
1158} // namespace mozilla