| File: | var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp |
| Warning: | line 166, column 12 Value stored to 'rv' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 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 "mozilla/JSONStringWriteFuncs.h" |
| 8 | #include "mozilla/StaticPrefs_dom.h" |
| 9 | #include "mozilla/dom/EndpointForReportChild.h" |
| 10 | #include "mozilla/dom/Fetch.h" |
| 11 | #include "mozilla/dom/Navigator.h" |
| 12 | #include "mozilla/dom/Promise.h" |
| 13 | #include "mozilla/dom/ReportBody.h" |
| 14 | #include "mozilla/dom/ReportDeliver.h" |
| 15 | #include "mozilla/dom/Request.h" |
| 16 | #include "mozilla/dom/RequestBinding.h" |
| 17 | #include "mozilla/dom/Response.h" |
| 18 | #include "mozilla/dom/RootedDictionary.h" |
| 19 | #include "mozilla/ipc/BackgroundChild.h" |
| 20 | #include "mozilla/ipc/PBackgroundChild.h" |
| 21 | #include "mozilla/ipc/PBackgroundSharedTypes.h" |
| 22 | #include "nsGlobalWindowInner.h" |
| 23 | #include "nsIGlobalObject.h" |
| 24 | #include "nsIXPConnect.h" |
| 25 | #include "nsNetUtil.h" |
| 26 | #include "nsStringStream.h" |
| 27 | |
| 28 | namespace mozilla::dom { |
| 29 | |
| 30 | namespace { |
| 31 | |
| 32 | StaticRefPtr<ReportDeliver> gReportDeliver; |
| 33 | |
| 34 | class ReportFetchHandler final : public PromiseNativeHandler { |
| 35 | public: |
| 36 | NS_DECL_ISUPPORTSpublic: virtual nsresult QueryInterface(const nsIID& aIID , void** aInstancePtr) override; virtual MozExternalRefCountType AddRef(void) override; virtual MozExternalRefCountType Release (void) override; using HasThreadSafeRefCnt = std::false_type; protected: nsAutoRefCnt mRefCnt; nsAutoOwningThread _mOwningThread ; public: |
| 37 | |
| 38 | explicit ReportFetchHandler( |
| 39 | const nsTArray<ReportDeliver::ReportData>& aReportData) |
| 40 | : mReports(aReportData.Clone()) {} |
| 41 | |
| 42 | void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue, |
| 43 | ErrorResult& aRv) override { |
| 44 | if (!gReportDeliver) { |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | if (NS_WARN_IF(!aValue.isObject())NS_warn_if_impl(!aValue.isObject(), "!aValue.isObject()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 48)) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | JS::Rooted<JSObject*> obj(aCx, &aValue.toObject()); |
| 53 | MOZ_ASSERT(obj)do { static_assert( mozilla::detail::AssertionConditionType< decltype(obj)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(obj))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("obj", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 53); AnnotateMozCrashReason("MOZ_ASSERT" "(" "obj" ")"); do { *((volatile int*)__null) = 53; __attribute__((nomerge)) :: abort(); } while (false); } } while (false); |
| 54 | |
| 55 | { |
| 56 | Response* response = nullptr; |
| 57 | if (NS_WARN_IF(NS_FAILED(UNWRAP_OBJECT(Response, &obj, response)))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(mozilla ::dom::binding_detail::UnwrapObjectWithCrossOriginAsserts< mozilla::dom::prototypes::id::Response, mozilla::dom::Response_Binding ::NativeType>(&obj, response))), 0))), "NS_FAILED(UNWRAP_OBJECT(Response, &obj, response))" , "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 57)) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | if (response->Status() == 410) { |
| 62 | mozilla::ipc::PBackgroundChild* actorChild = |
| 63 | mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread(); |
| 64 | |
| 65 | for (const auto& report : mReports) { |
| 66 | mozilla::ipc::PrincipalInfo principalInfo; |
| 67 | nsresult rv = |
| 68 | PrincipalToPrincipalInfo(report.mPrincipal, &principalInfo); |
| 69 | 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/dom/reporting/ReportDeliver.cpp" , 69)) { |
| 70 | continue; |
| 71 | } |
| 72 | |
| 73 | actorChild->SendRemoveEndpoint(report.mGroupName, report.mEndpointURL, |
| 74 | principalInfo); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue, |
| 81 | ErrorResult& aRv) override { |
| 82 | if (gReportDeliver) { |
| 83 | for (auto& report : mReports) { |
| 84 | ++report.mFailures; |
| 85 | gReportDeliver->AppendReportData(report); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | private: |
| 91 | ~ReportFetchHandler() = default; |
| 92 | |
| 93 | nsTArray<ReportDeliver::ReportData> mReports; |
| 94 | }; |
| 95 | |
| 96 | NS_IMPL_ISUPPORTS0(ReportFetchHandler)MozExternalRefCountType ReportFetchHandler::AddRef(void) { static_assert (!std::is_destructible_v<ReportFetchHandler>, "Reference-counted class " "ReportFetchHandler" " should not have a public destructor. " "Make this class's destructor non-public"); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(int32_t (mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 96); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 96; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("ReportFetchHandler" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("ReportFetchHandler" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"ReportFetchHandler\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 96); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"ReportFetchHandler\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 96; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("ReportFetchHandler" " not thread-safe"); nsrefcnt count = ++ mRefCnt; NS_LogAddRef((this), (count), ("ReportFetchHandler") , (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType ReportFetchHandler::Release(void) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 96); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { *((volatile int*)__null) = 96 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("ReportFetchHandler" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("ReportFetchHandler" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"ReportFetchHandler\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 96); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"ReportFetchHandler\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 96; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("ReportFetchHandler" " not thread-safe"); const char* const nametmp = "ReportFetchHandler"; nsrefcnt count = --mRefCnt; NS_LogRelease ((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult ReportFetchHandler ::QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "QueryInterface requires a non-NULL destination!", "aInstancePtr" , "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 96); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<ReportFetchHandler, nsISupports>, int32_t ( reinterpret_cast<char*>(static_cast<nsISupports*> ((ReportFetchHandler*)0x1000)) - reinterpret_cast<char*> ((ReportFetchHandler*)0x1000))}, { nullptr, 0 } } ; static_assert ((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface" ); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID , aInstancePtr, table); return rv; } |
| 97 | |
| 98 | class ReportJSONWriter final : public JSONWriter { |
| 99 | public: |
| 100 | explicit ReportJSONWriter(JSONStringWriteFunc<nsAutoCString>& aOutput) |
| 101 | : JSONWriter(aOutput) {} |
| 102 | |
| 103 | void JSONProperty(const Span<const char>& aProperty, |
| 104 | const Span<const char>& aJSON) { |
| 105 | Separator(); |
| 106 | PropertyNameAndColon(aProperty); |
| 107 | mWriter.Write(aJSON); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | void SendReports(nsTArray<ReportDeliver::ReportData>& aReports, |
| 112 | const nsCString& aEndPointUrl, nsIPrincipal* aPrincipal) { |
| 113 | if (NS_WARN_IF(aReports.IsEmpty())NS_warn_if_impl(aReports.IsEmpty(), "aReports.IsEmpty()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 113)) { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | nsIXPConnect* xpc = nsContentUtils::XPConnect(); |
| 118 | MOZ_ASSERT(xpc, "This should never be null!")do { static_assert( mozilla::detail::AssertionConditionType< decltype(xpc)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(xpc))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("xpc" " (" "This should never be null!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 118); AnnotateMozCrashReason("MOZ_ASSERT" "(" "xpc" ") (" "This should never be null!" ")"); do { *((volatile int*)__null) = 118; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 119 | |
| 120 | nsCOMPtr<nsIGlobalObject> globalObject; |
| 121 | { |
| 122 | AutoJSAPI jsapi; |
| 123 | jsapi.Init(); |
| 124 | |
| 125 | JSContext* cx = jsapi.cx(); |
| 126 | JS::Rooted<JSObject*> sandbox(cx); |
| 127 | nsresult rv = xpc->CreateSandbox(cx, aPrincipal, sandbox.address()); |
| 128 | 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/dom/reporting/ReportDeliver.cpp" , 128)) { |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | // The JSContext is not in a realm, so CreateSandbox returned an unwrapped |
| 133 | // global. |
| 134 | MOZ_ASSERT(JS_IsGlobalObject(sandbox))do { static_assert( mozilla::detail::AssertionConditionType< decltype(JS_IsGlobalObject(sandbox))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(JS_IsGlobalObject(sandbox))) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("JS_IsGlobalObject(sandbox)" , "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 134); AnnotateMozCrashReason("MOZ_ASSERT" "(" "JS_IsGlobalObject(sandbox)" ")"); do { *((volatile int*)__null) = 134; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 135 | |
| 136 | globalObject = xpc::NativeGlobal(sandbox); |
| 137 | } |
| 138 | |
| 139 | if (NS_WARN_IF(!globalObject)NS_warn_if_impl(!globalObject, "!globalObject", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 139)) { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | // The body |
| 144 | JSONStringWriteFunc<nsAutoCString> body; |
| 145 | ReportJSONWriter w(body); |
| 146 | |
| 147 | w.StartArrayElement(); |
| 148 | for (const auto& report : aReports) { |
| 149 | MOZ_ASSERT(report.mPrincipal == aPrincipal)do { static_assert( mozilla::detail::AssertionConditionType< decltype(report.mPrincipal == aPrincipal)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(report.mPrincipal == aPrincipal ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "report.mPrincipal == aPrincipal", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 149); AnnotateMozCrashReason("MOZ_ASSERT" "(" "report.mPrincipal == aPrincipal" ")"); do { *((volatile int*)__null) = 149; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 150 | MOZ_ASSERT(report.mEndpointURL == aEndPointUrl)do { static_assert( mozilla::detail::AssertionConditionType< decltype(report.mEndpointURL == aEndPointUrl)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(report.mEndpointURL == aEndPointUrl ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "report.mEndpointURL == aEndPointUrl", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 150); AnnotateMozCrashReason("MOZ_ASSERT" "(" "report.mEndpointURL == aEndPointUrl" ")"); do { *((volatile int*)__null) = 150; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 151 | w.StartObjectElement(); |
| 152 | w.IntProperty("age", |
| 153 | (TimeStamp::Now() - report.mCreationTime).ToMilliseconds()); |
| 154 | w.StringProperty("type", NS_ConvertUTF16toUTF8(report.mType)); |
| 155 | w.StringProperty("url", NS_ConvertUTF16toUTF8(report.mURL)); |
| 156 | w.StringProperty("user_agent", NS_ConvertUTF16toUTF8(report.mUserAgent)); |
| 157 | w.JSONProperty(MakeStringSpan("body"), |
| 158 | Span<const char>(report.mReportBodyJSON.Data(), |
| 159 | report.mReportBodyJSON.Length())); |
| 160 | w.EndObject(); |
| 161 | } |
| 162 | w.EndArray(); |
| 163 | |
| 164 | // The body as stream |
| 165 | nsCOMPtr<nsIInputStream> streamBody; |
| 166 | nsresult rv = |
Value stored to 'rv' during its initialization is never read | |
| 167 | NS_NewCStringInputStream(getter_AddRefs(streamBody), body.StringCRef()); |
| 168 | |
| 169 | // Headers |
| 170 | IgnoredErrorResult error; |
| 171 | RefPtr<InternalHeaders> internalHeaders = |
| 172 | new InternalHeaders(HeadersGuardEnum::Request); |
| 173 | internalHeaders->Set("Content-Type"_ns, "application/reports+json"_ns, error); |
| 174 | if (NS_WARN_IF(error.Failed())NS_warn_if_impl(error.Failed(), "error.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 174)) { |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | // URL and fragments |
| 179 | nsCOMPtr<nsIURI> uri; |
| 180 | rv = NS_NewURI(getter_AddRefs(uri), aEndPointUrl); |
| 181 | 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/dom/reporting/ReportDeliver.cpp" , 181)) { |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | nsCOMPtr<nsIURI> uriClone; |
| 186 | rv = NS_GetURIWithoutRef(uri, getter_AddRefs(uriClone)); |
| 187 | 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/dom/reporting/ReportDeliver.cpp" , 187)) { |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | nsAutoCString uriSpec; |
| 192 | rv = uriClone->GetSpec(uriSpec); |
| 193 | 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/dom/reporting/ReportDeliver.cpp" , 193)) { |
| 194 | return; |
| 195 | } |
| 196 | |
| 197 | nsAutoCString uriFragment; |
| 198 | rv = uri->GetRef(uriFragment); |
| 199 | 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/dom/reporting/ReportDeliver.cpp" , 199)) { |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | auto internalRequest = MakeSafeRefPtr<InternalRequest>(uriSpec, uriFragment); |
| 204 | |
| 205 | internalRequest->SetMethod("POST"_ns); |
| 206 | internalRequest->SetBody(streamBody, body.StringCRef().Length()); |
| 207 | internalRequest->SetHeaders(internalHeaders); |
| 208 | internalRequest->SetSkipServiceWorker(); |
| 209 | // TODO: internalRequest->SetContentPolicyType(TYPE_REPORT); |
| 210 | internalRequest->SetMode(RequestMode::Cors); |
| 211 | internalRequest->SetCredentialsMode(RequestCredentials::Same_origin); |
| 212 | |
| 213 | RefPtr<Request> request = |
| 214 | new Request(globalObject, std::move(internalRequest), nullptr); |
| 215 | |
| 216 | RequestOrUTF8String fetchInput; |
| 217 | fetchInput.SetAsRequest() = request; |
| 218 | |
| 219 | RootedDictionary<RequestInit> requestInit(RootingCx()); |
| 220 | RefPtr<Promise> promise = FetchRequest(globalObject, fetchInput, requestInit, |
| 221 | CallerType::NonSystem, error); |
| 222 | if (error.Failed()) { |
| 223 | for (auto& report : aReports) { |
| 224 | ++report.mFailures; |
| 225 | if (gReportDeliver) { |
| 226 | gReportDeliver->AppendReportData(report); |
| 227 | } |
| 228 | } |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | RefPtr<ReportFetchHandler> handler = new ReportFetchHandler(aReports); |
| 233 | promise->AppendNativeHandler(handler); |
| 234 | } |
| 235 | |
| 236 | } // namespace |
| 237 | |
| 238 | /* static */ |
| 239 | void ReportDeliver::Record(nsPIDOMWindowInner* aWindow, const nsAString& aType, |
| 240 | const nsAString& aGroupName, const nsAString& aURL, |
| 241 | ReportBody* aBody) { |
| 242 | 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/dom/reporting/ReportDeliver.cpp" , 242); AnnotateMozCrashReason("MOZ_ASSERT" "(" "NS_IsMainThread()" ")"); do { *((volatile int*)__null) = 242; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 243 | MOZ_ASSERT(aWindow)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aWindow)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(aWindow))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("aWindow", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 243); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aWindow" ")" ); do { *((volatile int*)__null) = 243; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 244 | MOZ_ASSERT(aBody)do { static_assert( mozilla::detail::AssertionConditionType< decltype(aBody)>::isValid, "invalid assertion condition"); if ((__builtin_expect(!!(!(!!(aBody))), 0))) { do { } while ( false); MOZ_ReportAssertionFailure("aBody", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 244); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aBody" ")"); do { *((volatile int*)__null) = 244; __attribute__((nomerge) ) ::abort(); } while (false); } } while (false); |
| 245 | |
| 246 | JSONStringWriteFunc<nsAutoCString> reportBodyJSON; |
| 247 | ReportJSONWriter w(reportBodyJSON); |
| 248 | |
| 249 | w.Start(); |
| 250 | aBody->ToJSON(w); |
| 251 | w.End(); |
| 252 | |
| 253 | nsCOMPtr<nsIPrincipal> principal = |
| 254 | nsGlobalWindowInner::Cast(aWindow)->GetPrincipal(); |
| 255 | if (NS_WARN_IF(!principal)NS_warn_if_impl(!principal, "!principal", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 255)) { |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | mozilla::ipc::PrincipalInfo principalInfo; |
| 260 | nsresult rv = PrincipalToPrincipalInfo(principal, &principalInfo); |
| 261 | 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/dom/reporting/ReportDeliver.cpp" , 261)) { |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | mozilla::ipc::PBackgroundChild* actorChild = |
| 266 | mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread(); |
| 267 | |
| 268 | PEndpointForReportChild* actor = |
| 269 | actorChild->SendPEndpointForReportConstructor(nsString(aGroupName), |
| 270 | principalInfo); |
| 271 | if (NS_WARN_IF(!actor)NS_warn_if_impl(!actor, "!actor", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 271)) { |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | ReportData data; |
| 276 | data.mType = aType; |
| 277 | data.mGroupName = aGroupName; |
| 278 | data.mURL = aURL; |
| 279 | data.mCreationTime = TimeStamp::Now(); |
| 280 | data.mReportBodyJSON = std::move(reportBodyJSON).StringRRef(); |
| 281 | data.mPrincipal = principal; |
| 282 | data.mFailures = 0; |
| 283 | |
| 284 | Navigator* navigator = aWindow->Navigator(); |
| 285 | MOZ_ASSERT(navigator)do { static_assert( mozilla::detail::AssertionConditionType< decltype(navigator)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(navigator))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("navigator", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 285); AnnotateMozCrashReason("MOZ_ASSERT" "(" "navigator" ")" ); do { *((volatile int*)__null) = 285; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 286 | |
| 287 | IgnoredErrorResult error; |
| 288 | navigator->GetUserAgent(data.mUserAgent, CallerType::NonSystem, error); |
| 289 | if (NS_WARN_IF(error.Failed())NS_warn_if_impl(error.Failed(), "error.Failed()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 289)) { |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | static_cast<EndpointForReportChild*>(actor)->Initialize(data); |
| 294 | } |
| 295 | |
| 296 | /* static */ |
| 297 | void ReportDeliver::Fetch(const ReportData& aReportData) { |
| 298 | if (!gReportDeliver) { |
| 299 | RefPtr<ReportDeliver> rd = new ReportDeliver(); |
| 300 | |
| 301 | nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); |
| 302 | if (NS_WARN_IF(!obs)NS_warn_if_impl(!obs, "!obs", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 302)) { |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | obs->AddObserver(rd, NS_XPCOM_SHUTDOWN_OBSERVER_ID"xpcom-shutdown", false); |
| 307 | gReportDeliver = rd; |
| 308 | } |
| 309 | |
| 310 | gReportDeliver->AppendReportData(aReportData); |
| 311 | } |
| 312 | |
| 313 | void ReportDeliver::AppendReportData(const ReportData& aReportData) { |
| 314 | if (aReportData.mFailures > |
| 315 | StaticPrefs::dom_reporting_delivering_maxFailures()) { |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | if (NS_WARN_IF(!mReportQueue.AppendElement(aReportData, fallible))NS_warn_if_impl(!mReportQueue.AppendElement(aReportData, fallible ), "!mReportQueue.AppendElement(aReportData, fallible)", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 319)) { |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | while (mReportQueue.Length() > |
| 324 | StaticPrefs::dom_reporting_delivering_maxReports()) { |
| 325 | mReportQueue.RemoveElementAt(0); |
| 326 | } |
| 327 | |
| 328 | RefPtr<ReportDeliver> self{this}; |
| 329 | nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction( |
| 330 | "ReportDeliver::CallNotify", [self]() { self->Notify(); }); |
| 331 | |
| 332 | NS_DispatchToCurrentThreadQueue( |
| 333 | runnable.forget(), StaticPrefs::dom_reporting_delivering_timeout() * 1000, |
| 334 | EventQueuePriority::Idle); |
| 335 | } |
| 336 | |
| 337 | void ReportDeliver::Notify() { |
| 338 | nsTArray<ReportData> reports = std::move(mReportQueue); |
| 339 | |
| 340 | // group reports by endpoint and nsIPrincipal |
| 341 | std::map<std::pair<nsCString, nsCOMPtr<nsIPrincipal>>, nsTArray<ReportData>> |
| 342 | reportsByPrincipal; |
| 343 | for (ReportData& report : reports) { |
| 344 | auto already_seen = |
| 345 | reportsByPrincipal.find({report.mEndpointURL, report.mPrincipal}); |
| 346 | if (already_seen == reportsByPrincipal.end()) { |
| 347 | reportsByPrincipal.emplace( |
| 348 | std::make_pair(report.mEndpointURL, report.mPrincipal), |
| 349 | nsTArray<ReportData>({report})); |
| 350 | } else { |
| 351 | already_seen->second.AppendElement(report); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | for (auto& iter : reportsByPrincipal) { |
| 356 | std::pair<nsCString, nsCOMPtr<nsIPrincipal>> key = iter.first; |
| 357 | nsTArray<ReportData>& value = iter.second; |
| 358 | nsCString url = key.first; |
| 359 | nsCOMPtr<nsIPrincipal> principal = key.second; |
| 360 | nsAutoCString u(url); |
| 361 | SendReports(value, url, principal); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | NS_IMETHODIMPnsresult |
| 366 | ReportDeliver::GetName(nsACString& aName) { |
| 367 | aName.AssignLiteral("ReportDeliver"); |
| 368 | return NS_OK; |
| 369 | } |
| 370 | |
| 371 | NS_IMETHODIMPnsresult |
| 372 | ReportDeliver::Observe(nsISupports* aSubject, const char* aTopic, |
| 373 | const char16_t* aData) { |
| 374 | MOZ_ASSERT(!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))do { static_assert( mozilla::detail::AssertionConditionType< decltype(!strcmp(aTopic, "xpcom-shutdown"))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!strcmp(aTopic, "xpcom-shutdown" )))), 0))) { do { } while (false); MOZ_ReportAssertionFailure ("!strcmp(aTopic, \"xpcom-shutdown\")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 374); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!strcmp(aTopic, \"xpcom-shutdown\")" ")"); do { *((volatile int*)__null) = 374; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); |
| 375 | |
| 376 | nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); |
| 377 | if (NS_WARN_IF(!obs)NS_warn_if_impl(!obs, "!obs", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 377)) { |
| 378 | return NS_OK; |
| 379 | } |
| 380 | |
| 381 | obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID"xpcom-shutdown"); |
| 382 | |
| 383 | gReportDeliver = nullptr; |
| 384 | return NS_OK; |
| 385 | } |
| 386 | |
| 387 | ReportDeliver::ReportDeliver() = default; |
| 388 | |
| 389 | ReportDeliver::~ReportDeliver() = default; |
| 390 | |
| 391 | NS_INTERFACE_MAP_BEGIN(ReportDeliver)nsresult ReportDeliver::QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak (NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!" , "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 391); MOZ_PretendNoReturn(); } } while (0); nsISupports* foundInterface ; |
| 392 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsISupports>)) foundInterface = static_cast <nsISupports*>(static_cast<nsIObserver*>(this)); else |
| 393 | NS_INTERFACE_MAP_ENTRY(nsIObserver)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsIObserver>)) foundInterface = static_cast <nsIObserver*>(this); else |
| 394 | NS_INTERFACE_MAP_ENTRY(nsINamed)if (aIID.Equals(mozilla::detail::kImplementedIID<std::remove_reference_t <decltype(*this)>, nsINamed>)) foundInterface = static_cast <nsINamed*>(this); else |
| 395 | NS_INTERFACE_MAP_ENDfoundInterface = 0; nsresult status; if (!foundInterface) { do { static_assert( mozilla::detail::AssertionConditionType< decltype(!aIID.Equals((nsISupports::COMTypeInfo<nsISupports , void>::kIID)))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!aIID.Equals((nsISupports::COMTypeInfo <nsISupports, void>::kIID))))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("!aIID.Equals((nsISupports::COMTypeInfo<nsISupports, void>::kIID))" , "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 395); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIID.Equals((nsISupports::COMTypeInfo<nsISupports, void>::kIID))" ")"); do { *((volatile int*)__null) = 395; __attribute__((nomerge )) ::abort(); } while (false); } } while (false); status = NS_NOINTERFACE ; } else { (foundInterface)->AddRef(); status = NS_OK; } * aInstancePtr = foundInterface; return status; } |
| 396 | |
| 397 | NS_IMPL_ADDREF(ReportDeliver)MozExternalRefCountType ReportDeliver::AddRef(void) { static_assert (!std::is_destructible_v<ReportDeliver>, "Reference-counted class " "ReportDeliver" " should not have a public destructor. " "Make this class's destructor non-public" ); do { static_assert( mozilla::detail::AssertionConditionType <decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 397); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { *((volatile int*)__null) = 397; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("ReportDeliver" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("ReportDeliver" != nullptr)) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"ReportDeliver\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 397); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"ReportDeliver\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 397; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("ReportDeliver" " not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef((this), (count), ("ReportDeliver" ), (uint32_t)(sizeof(*this))); return count; } |
| 398 | NS_IMPL_RELEASE(ReportDeliver)MozExternalRefCountType ReportDeliver::Release(void) { do { static_assert ( mozilla::detail::AssertionConditionType<decltype(int32_t (mRefCnt) > 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0 ))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 398); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { *((volatile int*)__null) = 398 ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("ReportDeliver" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("ReportDeliver" != nullptr)) ), 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"ReportDeliver\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/reporting/ReportDeliver.cpp" , 398); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"ReportDeliver\" != nullptr" ") (" "Must specify a name" ")"); do { *((volatile int*)__null ) = 398; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread .AssertOwnership("ReportDeliver" " not thread-safe"); const char * const nametmp = "ReportDeliver"; nsrefcnt count = --mRefCnt ; NS_LogRelease((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } |
| 399 | |
| 400 | } // namespace mozilla::dom |