Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp
Warning:line 140, column 12
Value stored to 'rv' during its initialization 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_layout_style3.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/layout/style -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/style -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 MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/layout/style -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/layout/style -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/layout/base -I /var/lib/jenkins/workspace/firefox-scan-build/layout/generic -I /var/lib/jenkins/workspace/firefox-scan-build/layout/xul -I /var/lib/jenkins/workspace/firefox-scan-build/dom/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/html -I /var/lib/jenkins/workspace/firefox-scan-build/dom/xul -I /var/lib/jenkins/workspace/firefox-scan-build/image -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/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../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-07-21-021012-413605-1 -x c++ Unified_cpp_layout_style3.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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#include "mozilla/css/StreamLoader.h"
8#include "mozilla/StaticPrefs_network.h"
9#include "mozilla/Encoding.h"
10#include "mozilla/glean/GleanMetrics.h"
11#include "mozilla/TaskQueue.h"
12#include "nsContentUtils.h"
13#include "nsIAsyncVerifyRedirectCallback.h"
14#include "nsIChannel.h"
15#include "nsIInputStream.h"
16#include "nsIThreadRetargetableRequest.h"
17#include "nsIStreamTransportService.h"
18#include "nsNetCID.h"
19#include "nsNetUtil.h"
20#include "nsProxyRelease.h"
21#include "nsServiceManagerUtils.h"
22
23namespace mozilla::css {
24
25StreamLoader::StreamLoader(SheetLoadData& aSheetLoadData)
26 : mSheetLoadData(&aSheetLoadData),
27 mStatus(NS_OK),
28 mMainThreadSheetLoadData(new nsMainThreadPtrHolder<SheetLoadData>(
29 "StreamLoader::SheetLoadData", mSheetLoadData, false)) {}
30
31StreamLoader::~StreamLoader() {
32#ifdef NIGHTLY_BUILD1
33 MOZ_RELEASE_ASSERT(mOnStopProcessingDone || mChannelOpenFailed)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mOnStopProcessingDone || mChannelOpenFailed)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(mOnStopProcessingDone || mChannelOpenFailed))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("mOnStopProcessingDone || mChannelOpenFailed"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 33); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "mOnStopProcessingDone || mChannelOpenFailed"
")"); do { *((volatile int*)__null) = 33; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
34#endif
35}
36
37NS_IMPL_ISUPPORTS(StreamLoader, nsIStreamListener,MozExternalRefCountType StreamLoader::AddRef(void) { static_assert
(!std::is_destructible_v<StreamLoader>, "Reference-counted class "
"StreamLoader" " 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/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
39; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); nsrefcnt count = ++mRefCnt
; NS_LogAddRef((this), (count), ("StreamLoader"), (uint32_t)(
sizeof(*this))); return count; } MozExternalRefCountType StreamLoader
::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/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 39
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); const char* const nametmp
= "StreamLoader"; nsrefcnt count = --mRefCnt; NS_LogRelease(
(this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete
(this); return 0; } return count; } nsresult StreamLoader::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/layout/style/StreamLoader.cpp"
, 39); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<StreamLoader, nsIStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsIThreadRetargetableStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIThreadRetargetableStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsIChannelEventSink>, int32_t( reinterpret_cast
<char*>(static_cast<nsIChannelEventSink*>((StreamLoader
*)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000
))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor
>, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsISupports>, int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener
*>((StreamLoader*)0x1000))) - reinterpret_cast<char*>
((StreamLoader*)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; }
38 nsIThreadRetargetableStreamListener, nsIChannelEventSink,MozExternalRefCountType StreamLoader::AddRef(void) { static_assert
(!std::is_destructible_v<StreamLoader>, "Reference-counted class "
"StreamLoader" " 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/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
39; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); nsrefcnt count = ++mRefCnt
; NS_LogAddRef((this), (count), ("StreamLoader"), (uint32_t)(
sizeof(*this))); return count; } MozExternalRefCountType StreamLoader
::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/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 39
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); const char* const nametmp
= "StreamLoader"; nsrefcnt count = --mRefCnt; NS_LogRelease(
(this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete
(this); return 0; } return count; } nsresult StreamLoader::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/layout/style/StreamLoader.cpp"
, 39); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<StreamLoader, nsIStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsIThreadRetargetableStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIThreadRetargetableStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsIChannelEventSink>, int32_t( reinterpret_cast
<char*>(static_cast<nsIChannelEventSink*>((StreamLoader
*)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000
))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor
>, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsISupports>, int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener
*>((StreamLoader*)0x1000))) - reinterpret_cast<char*>
((StreamLoader*)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; }
39 nsIInterfaceRequestor)MozExternalRefCountType StreamLoader::AddRef(void) { static_assert
(!std::is_destructible_v<StreamLoader>, "Reference-counted class "
"StreamLoader" " 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/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
39; __attribute__((nomerge)) ::abort(); } while (false); } }
while (false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); nsrefcnt count = ++mRefCnt
; NS_LogAddRef((this), (count), ("StreamLoader"), (uint32_t)(
sizeof(*this))); return count; } MozExternalRefCountType StreamLoader
::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/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 39
; __attribute__((nomerge)) ::abort(); } while (false); } } while
(false); do { static_assert( mozilla::detail::AssertionConditionType
<decltype("StreamLoader" != nullptr)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!("StreamLoader" != nullptr)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("\"StreamLoader\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"StreamLoader\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("StreamLoader" " not thread-safe"); const char* const nametmp
= "StreamLoader"; nsrefcnt count = --mRefCnt; NS_LogRelease(
(this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete
(this); return 0; } return count; } nsresult StreamLoader::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/layout/style/StreamLoader.cpp"
, 39); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<StreamLoader, nsIStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsIThreadRetargetableStreamListener>, int32_t
( reinterpret_cast<char*>(static_cast<nsIThreadRetargetableStreamListener
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsIChannelEventSink>, int32_t( reinterpret_cast
<char*>(static_cast<nsIChannelEventSink*>((StreamLoader
*)0x1000)) - reinterpret_cast<char*>((StreamLoader*)0x1000
))}, {&mozilla::detail::kImplementedIID<StreamLoader, nsIInterfaceRequestor
>, int32_t( reinterpret_cast<char*>(static_cast<nsIInterfaceRequestor
*>((StreamLoader*)0x1000)) - reinterpret_cast<char*>
((StreamLoader*)0x1000))}, {&mozilla::detail::kImplementedIID
<StreamLoader, nsISupports>, int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIStreamListener
*>((StreamLoader*)0x1000))) - reinterpret_cast<char*>
((StreamLoader*)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; }
40
41static uint32_t CalculateExpirationTime(nsIRequest* aRequest, nsIURI* aURI) {
42 auto info = nsContentUtils::GetSubresourceCacheValidationInfo(aRequest, aURI);
43
44 // For now, we never cache entries that we have to revalidate, or whose
45 // channel don't support caching.
46 if (info.mMustRevalidate || !info.mExpirationTime) {
47 return nsContentUtils::SecondsFromPRTime(PR_Now()) - 1;
48 }
49 return *info.mExpirationTime;
50}
51
52/* nsIRequestObserver implementation */
53NS_IMETHODIMPnsresult
54StreamLoader::OnStartRequest(nsIRequest* aRequest) {
55 MOZ_ASSERT(aRequest)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aRequest)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aRequest))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("aRequest", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 55); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aRequest" ")"
); do { *((volatile int*)__null) = 55; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
56 mRequest = aRequest;
57 mSheetLoadData->NotifyStart(aRequest);
58
59 // It's kinda bad to let Web content send a number that results
60 // in a potentially large allocation directly, but efficiency of
61 // compression bombs is so great that it doesn't make much sense
62 // to require a site to send one before going ahead and allocating.
63 if (nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest)) {
64 int64_t length;
65 nsresult rv = channel->GetContentLength(&length);
66 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && length > 0) {
67 CheckedInt<nsACString::size_type> checkedLength(length);
68 if (!checkedLength.isValid()) {
69 return (mStatus = NS_ERROR_OUT_OF_MEMORY);
70 }
71 if (!mBytes.SetCapacity(checkedLength.value(), fallible)) {
72 return (mStatus = NS_ERROR_OUT_OF_MEMORY);
73 }
74 }
75 NS_GetFinalChannelURI(channel, getter_AddRefs(mFinalChannelURI));
76 nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
77 // we dont return on error here as the error is handled in
78 // SheetLoadData::VerifySheetReadyToParse
79 Unused << secMan->GetChannelResultPrincipal(
80 channel, getter_AddRefs(mChannelResultPrincipal));
81 }
82 if (nsCOMPtr<nsIThreadRetargetableRequest> rr = do_QueryInterface(aRequest)) {
83 nsCOMPtr<nsIEventTarget> sts =
84 do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/stream-transport-service;1");
85 RefPtr queue =
86 TaskQueue::Create(sts.forget(), "css::StreamLoader Delivery Queue");
87 rr->RetargetDeliveryTo(queue);
88 }
89
90 mSheetLoadData->AccumulateExpirationTime(
91 CalculateExpirationTime(aRequest, mSheetLoadData->mURI));
92
93 // We need to block block resolution of parse promise until we receive
94 // OnStopRequest on Main thread. This is necessary because parse promise
95 // resolution fires OnLoad event OnLoad event must not be dispatched until
96 // OnStopRequest in main thread is processed, for stuff like performance
97 // resource entries.
98 mSheetLoadData->mSheet->BlockParsePromise();
99
100 return NS_OK;
101}
102
103NS_IMETHODIMPnsresult
104StreamLoader::CheckListenerChain() { return NS_OK; }
105
106NS_IMETHODIMPnsresult
107StreamLoader::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
108 MOZ_ASSERT_IF(!StaticPrefs::network_send_OnDataFinished_cssLoader(),do { if (!StaticPrefs::network_send_OnDataFinished_cssLoader(
)) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(!mOnStopProcessingDone)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mOnStopProcessingDone))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!mOnStopProcessingDone"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 109); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOnStopProcessingDone"
")"); do { *((volatile int*)__null) = 109; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
109 !mOnStopProcessingDone)do { if (!StaticPrefs::network_send_OnDataFinished_cssLoader(
)) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(!mOnStopProcessingDone)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mOnStopProcessingDone))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("!mOnStopProcessingDone"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 109); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mOnStopProcessingDone"
")"); do { *((volatile int*)__null) = 109; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false); } } while (
false)
;
110
111 // StreamLoader::OnStopRequest can get triggered twice for a request.
112 // Once from the path
113 // nsIThreadRetargetableStreamListener::OnDataFinished->StreamLoader::OnDataFinished
114 // (non-main thread) and
115 // once from nsIRequestObserver::OnStopRequest path (main thread). It is
116 // guaranteed that we will always get
117 // nsIThreadRetargetableStreamListener::OnDataFinished trigger first and this
118 // is always followed by nsIRequestObserver::OnStopRequest
119
120 // If we are executing OnStopRequest OMT, we need to block resolution of parse
121 // promise and unblock again if we are executing this in main thread.
122 // Resolution of parse promise fires onLoadEvent and this should not happen
123 // before main thread OnStopRequest is dispatched.
124 if (NS_IsMainThread()) {
125 if (mOnDataFinishedTime) {
126 // collect telemetry for the delta between OnDataFinished and
127 // OnStopRequest
128 TimeDuration delta = (TimeStamp::Now() - mOnDataFinishedTime);
129 glean::networking::http_content_cssloader_ondatafinished_to_onstop_delay
130 .AccumulateRawDuration(delta);
131 }
132 mSheetLoadData->mSheet->UnblockParsePromise();
133 }
134
135 if (mOnStopProcessingDone) {
136 return NS_OK;
137 }
138 mOnStopProcessingDone = true;
139
140 nsresult rv = mStatus;
Value stored to 'rv' during its initialization is never read
141 // Decoded data
142 nsCString utf8String;
143 {
144 nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
145
146 if (NS_IsMainThread()) {
147 channel->SetNotificationCallbacks(nullptr);
148 }
149
150 if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) {
151 mSheetLoadData->VerifySheetReadyToParse(mStatus, ""_ns, ""_ns, channel,
152 mFinalChannelURI,
153 mChannelResultPrincipal);
154
155 if (!NS_IsMainThread()) {
156 // When processing OMT, we have code paths in VerifySheetReadyToParse
157 // that are main-thread only. We bail on such scenarios and continue
158 // processing them on main thread OnStopRequest.
159 mOnStopProcessingDone = false;
160 }
161 return mStatus;
162 }
163
164 rv = mSheetLoadData->VerifySheetReadyToParse(aStatus, mBOMBytes, mBytes,
165 channel, mFinalChannelURI,
166 mChannelResultPrincipal);
167 if (rv != NS_OK_PARSE_SHEET) {
168 if (!NS_IsMainThread()) {
169 mOnStopProcessingDone = false;
170 }
171 return rv;
172 }
173
174 // At this point all the conditions that requires us to run on main
175 // are checked in VerifySheetReadyToParse
176
177 // BOM detection generally happens during the write callback, but that
178 // won't have happened if fewer than three bytes were received.
179 if (mEncodingFromBOM.isNothing()) {
180 HandleBOM();
181 MOZ_ASSERT(mEncodingFromBOM.isSome())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mEncodingFromBOM.isSome())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mEncodingFromBOM.isSome())))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("mEncodingFromBOM.isSome()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 181); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isSome()"
")"); do { *((volatile int*)__null) = 181; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
182 }
183 // Hold the nsStringBuffer for the bytes from the stack to ensure release
184 // after its scope ends
185 nsCString bytes = std::move(mBytes);
186 // The BOM handling has happened, but we still may not have an encoding if
187 // there was no BOM. Ensure we have one.
188 const Encoding* encoding = mEncodingFromBOM.value();
189 if (!encoding) {
190 // No BOM
191 encoding = mSheetLoadData->DetermineNonBOMEncoding(bytes, channel);
192 }
193 mSheetLoadData->mEncoding = encoding;
194
195 size_t validated = 0;
196 if (encoding == UTF_8_ENCODING) {
197 validated = Encoding::UTF8ValidUpTo(bytes);
198 }
199
200 if (validated == bytes.Length()) {
201 // Either this is UTF-8 and all valid, or it's not UTF-8 but is an empty
202 // string. This assumes that an empty string in any encoding decodes to
203 // empty string, which seems like a plausible assumption.
204 utf8String = std::move(bytes);
205 } else {
206 rv = encoding->DecodeWithoutBOMHandling(bytes, utf8String, validated);
207 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/layout/style/StreamLoader.cpp"
, 207); return rv; } } while (false)
;
208 }
209 } // run destructor for `bytes`
210
211 // For reasons I don't understand, factoring the below lines into
212 // a method on SheetLoadData resulted in a linker error. Hence,
213 // accessing fields of mSheetLoadData from here.
214 mSheetLoadData->mLoader->ParseSheet(utf8String, mMainThreadSheetLoadData,
215 Loader::AllowAsyncParse::Yes);
216
217 mRequest = nullptr;
218
219 return NS_OK;
220}
221
222/* nsIStreamListener implementation */
223NS_IMETHODIMPnsresult
224StreamLoader::OnDataAvailable(nsIRequest*, nsIInputStream* aInputStream,
225 uint64_t, uint32_t aCount) {
226 if (NS_FAILED(mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(mStatus)), 0)))) {
227 return mStatus;
228 }
229 uint32_t dummy;
230 return aInputStream->ReadSegments(WriteSegmentFun, this, aCount, &dummy);
231}
232
233void StreamLoader::HandleBOM() {
234 MOZ_ASSERT(mEncodingFromBOM.isNothing())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mEncodingFromBOM.isNothing())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mEncodingFromBOM.isNothing()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mEncodingFromBOM.isNothing()", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 234); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mEncodingFromBOM.isNothing()"
")"); do { *((volatile int*)__null) = 234; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
235 MOZ_ASSERT(mBytes.IsEmpty())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mBytes.IsEmpty())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mBytes.IsEmpty()))), 0))) { do
{ } while (false); MOZ_ReportAssertionFailure("mBytes.IsEmpty()"
, "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 235); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mBytes.IsEmpty()"
")"); do { *((volatile int*)__null) = 235; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
236
237 auto [encoding, bomLength] = Encoding::ForBOM(mBOMBytes);
238 mEncodingFromBOM.emplace(encoding); // Null means no BOM.
239
240 // BOMs are three bytes at most, but may be fewer. Copy over anything
241 // that wasn't part of the BOM to mBytes. Note that we need to track
242 // any BOM bytes as well for SRI handling.
243 mBytes.Append(Substring(mBOMBytes, bomLength));
244 mBOMBytes.Truncate(bomLength);
245}
246
247NS_IMETHODIMPnsresult
248StreamLoader::OnDataFinished(nsresult aResult) {
249 if (StaticPrefs::network_send_OnDataFinished_cssLoader()) {
250 MOZ_ASSERT(mOnDataFinishedTime.IsNull(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mOnDataFinishedTime.IsNull())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mOnDataFinishedTime.IsNull()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mOnDataFinishedTime.IsNull()" " (" "OnDataFinished should only be called once"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 251); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mOnDataFinishedTime.IsNull()"
") (" "OnDataFinished should only be called once" ")"); do {
*((volatile int*)__null) = 251; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
251 "OnDataFinished should only be called once")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mOnDataFinishedTime.IsNull())>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mOnDataFinishedTime.IsNull()
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"mOnDataFinishedTime.IsNull()" " (" "OnDataFinished should only be called once"
")", "/var/lib/jenkins/workspace/firefox-scan-build/layout/style/StreamLoader.cpp"
, 251); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mOnDataFinishedTime.IsNull()"
") (" "OnDataFinished should only be called once" ")"); do {
*((volatile int*)__null) = 251; __attribute__((nomerge)) ::abort
(); } while (false); } } while (false)
;
252 mOnDataFinishedTime = TimeStamp::Now();
253 return OnStopRequest(mRequest, aResult);
254 }
255
256 return NS_OK;
257}
258
259NS_IMETHODIMPnsresult
260StreamLoader::GetInterface(const nsIID& aIID, void** aResult) {
261 if (aIID.Equals(NS_GET_IID(nsIChannelEventSink)(nsIChannelEventSink::COMTypeInfo<nsIChannelEventSink, void
>::kIID)
)) {
262 return QueryInterface(aIID, aResult);
263 }
264
265 return NS_NOINTERFACE;
266}
267
268nsresult StreamLoader::AsyncOnChannelRedirect(
269 nsIChannel* aOld, nsIChannel* aNew, uint32_t aFlags,
270 nsIAsyncVerifyRedirectCallback* aCallback) {
271 mSheetLoadData->AccumulateExpirationTime(
272 CalculateExpirationTime(aOld, mSheetLoadData->mURI));
273
274 aCallback->OnRedirectVerifyCallback(NS_OK);
275
276 return NS_OK;
277}
278
279nsresult StreamLoader::WriteSegmentFun(nsIInputStream*, void* aClosure,
280 const char* aSegment, uint32_t,
281 uint32_t aCount, uint32_t* aWriteCount) {
282 *aWriteCount = 0;
283 StreamLoader* self = static_cast<StreamLoader*>(aClosure);
284 if (NS_FAILED(self->mStatus)((bool)(__builtin_expect(!!(NS_FAILED_impl(self->mStatus))
, 0)))
) {
285 return self->mStatus;
286 }
287
288 // If we haven't done BOM detection yet, divert bytes into the special buffer.
289 if (self->mEncodingFromBOM.isNothing()) {
290 size_t bytesToCopy = std::min<size_t>(3 - self->mBOMBytes.Length(), aCount);
291 self->mBOMBytes.Append(aSegment, bytesToCopy);
292 aSegment += bytesToCopy;
293 *aWriteCount += bytesToCopy;
294 aCount -= bytesToCopy;
295
296 if (self->mBOMBytes.Length() == 3) {
297 self->HandleBOM();
298 } else {
299 return NS_OK;
300 }
301 }
302
303 if (!self->mBytes.Append(aSegment, aCount, fallible)) {
304 self->mBytes.Truncate();
305 return (self->mStatus = NS_ERROR_OUT_OF_MEMORY);
306 }
307
308 *aWriteCount += aCount;
309 return NS_OK;
310}
311
312} // namespace mozilla::css