Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp
Warning:line 70, column 3
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_antitracking1.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/toolkit/components/antitracking -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/components/antitracking -resource-dir /usr/lib/llvm-20/lib/clang/20 -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 _GLIBCXX_ASSERTIONS -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/toolkit/components/antitracking -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/components/antitracking -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/base -I /var/lib/jenkins/workspace/firefox-scan-build/netwerk/protocol/http -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/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-20/lib/clang/20/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 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -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-2025-01-20-090804-167946-1 -x c++ Unified_cpp_antitracking1.cpp
1/* vim: set ts=8 sts=2 et sw=2 tw=80: */
2/* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6#include "URLQueryStringStripper.h"
7
8#include "mozilla/ClearOnShutdown.h"
9#include "mozilla/StaticPrefs_privacy.h"
10#include "mozilla/StaticPtr.h"
11#include "mozilla/Unused.h"
12#include "mozilla/Telemetry.h"
13
14#include "nsEffectiveTLDService.h"
15#include "nsISupportsImpl.h"
16#include "nsIURI.h"
17#include "nsIURIMutator.h"
18#include "nsUnicharUtils.h"
19#include "nsURLHelper.h"
20#include "nsNetUtil.h"
21#include "mozilla/dom/StripOnShareRuleBinding.h"
22
23namespace {
24
25mozilla::StaticRefPtr<mozilla::URLQueryStringStripper> gQueryStringStripper;
26
27static const char kQueryStrippingEnabledPref[] =
28 "privacy.query_stripping.enabled";
29static const char kQueryStrippingEnabledPBMPref[] =
30 "privacy.query_stripping.enabled.pbmode";
31static const char kQueryStrippingOnShareEnabledPref[] =
32 "privacy.query_stripping.strip_on_share.enabled";
33
34} // namespace
35
36namespace mozilla {
37
38NS_IMPL_ISUPPORTS(URLQueryStringStripper, nsIObserver,MozExternalRefCountType URLQueryStringStripper::AddRef(void) {
static_assert(!std::is_destructible_v<URLQueryStringStripper
>, "Reference-counted class " "URLQueryStringStripper" " 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/toolkit/components/antitracking/URLQueryStringStripper.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("URLQueryStringStripper" != nullptr)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!("URLQueryStringStripper" != nullptr))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("\"URLQueryStringStripper\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"URLQueryStringStripper\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("URLQueryStringStripper" " not thread-safe"); nsrefcnt count
= ++mRefCnt; NS_LogAddRef((this), (count), ("URLQueryStringStripper"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
URLQueryStringStripper::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/toolkit/components/antitracking/URLQueryStringStripper.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("URLQueryStringStripper" != nullptr)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!("URLQueryStringStripper" != nullptr))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("\"URLQueryStringStripper\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"URLQueryStringStripper\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("URLQueryStringStripper" " not thread-safe"); const char* const
nametmp = "URLQueryStringStripper"; nsrefcnt count = --mRefCnt
; NS_LogRelease((this), (count), (nametmp)); if (count == 0) {
mRefCnt = 1; delete (this); return 0; } return count; } nsresult
URLQueryStringStripper::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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 39); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(3 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<URLQueryStringStripper, nsIObserver>,
int32_t( reinterpret_cast<char*>(static_cast<nsIObserver
*>((URLQueryStringStripper*)0x1000)) - reinterpret_cast<
char*>((URLQueryStringStripper*)0x1000))}, {&mozilla::
detail::kImplementedIID<URLQueryStringStripper, nsIURLQueryStringStripper
>, int32_t( reinterpret_cast<char*>(static_cast<nsIURLQueryStringStripper
*>((URLQueryStringStripper*)0x1000)) - reinterpret_cast<
char*>((URLQueryStringStripper*)0x1000))}, {&mozilla::
detail::kImplementedIID<URLQueryStringStripper, nsIURLQueryStrippingListObserver
>, int32_t( reinterpret_cast<char*>(static_cast<nsIURLQueryStrippingListObserver
*>((URLQueryStringStripper*)0x1000)) - reinterpret_cast<
char*>((URLQueryStringStripper*)0x1000))}, {&mozilla::
detail::kImplementedIID<URLQueryStringStripper, nsISupports
>, int32_t(reinterpret_cast<char*>(static_cast<nsISupports
*>( static_cast<nsIObserver*>((URLQueryStringStripper
*)0x1000))) - reinterpret_cast<char*>((URLQueryStringStripper
*)0x1000))}, { nullptr, 0 } } ; static_assert(std::size(table
) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI
(static_cast<void*>(this), aIID, aInstancePtr, table); return
rv; }
39 nsIURLQueryStringStripper, nsIURLQueryStrippingListObserver)MozExternalRefCountType URLQueryStringStripper::AddRef(void) {
static_assert(!std::is_destructible_v<URLQueryStringStripper
>, "Reference-counted class " "URLQueryStringStripper" " 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/toolkit/components/antitracking/URLQueryStringStripper.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("URLQueryStringStripper" != nullptr)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!("URLQueryStringStripper" != nullptr))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("\"URLQueryStringStripper\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"URLQueryStringStripper\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("URLQueryStringStripper" " not thread-safe"); nsrefcnt count
= ++mRefCnt; NS_LogAddRef((this), (count), ("URLQueryStringStripper"
), (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType
URLQueryStringStripper::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/toolkit/components/antitracking/URLQueryStringStripper.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("URLQueryStringStripper" != nullptr)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!("URLQueryStringStripper" != nullptr))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("\"URLQueryStringStripper\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 39); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"URLQueryStringStripper\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 39; __attribute__((nomerge)) ::abort(); } while (false); }
} while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership
("URLQueryStringStripper" " not thread-safe"); const char* const
nametmp = "URLQueryStringStripper"; nsrefcnt count = --mRefCnt
; NS_LogRelease((this), (count), (nametmp)); if (count == 0) {
mRefCnt = 1; delete (this); return 0; } return count; } nsresult
URLQueryStringStripper::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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 39); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(3 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<URLQueryStringStripper, nsIObserver>,
int32_t( reinterpret_cast<char*>(static_cast<nsIObserver
*>((URLQueryStringStripper*)0x1000)) - reinterpret_cast<
char*>((URLQueryStringStripper*)0x1000))}, {&mozilla::
detail::kImplementedIID<URLQueryStringStripper, nsIURLQueryStringStripper
>, int32_t( reinterpret_cast<char*>(static_cast<nsIURLQueryStringStripper
*>((URLQueryStringStripper*)0x1000)) - reinterpret_cast<
char*>((URLQueryStringStripper*)0x1000))}, {&mozilla::
detail::kImplementedIID<URLQueryStringStripper, nsIURLQueryStrippingListObserver
>, int32_t( reinterpret_cast<char*>(static_cast<nsIURLQueryStrippingListObserver
*>((URLQueryStringStripper*)0x1000)) - reinterpret_cast<
char*>((URLQueryStringStripper*)0x1000))}, {&mozilla::
detail::kImplementedIID<URLQueryStringStripper, nsISupports
>, int32_t(reinterpret_cast<char*>(static_cast<nsISupports
*>( static_cast<nsIObserver*>((URLQueryStringStripper
*)0x1000))) - reinterpret_cast<char*>((URLQueryStringStripper
*)0x1000))}, { nullptr, 0 } } ; static_assert(std::size(table
) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI
(static_cast<void*>(this), aIID, aInstancePtr, table); return
rv; }
40
41// static
42already_AddRefed<URLQueryStringStripper>
43URLQueryStringStripper::GetSingleton() {
44 if (!gQueryStringStripper) {
45 gQueryStringStripper = new URLQueryStringStripper();
46 // Check initial pref state and enable service. We can pass nullptr, because
47 // OnPrefChange doesn't rely on the args.
48 URLQueryStringStripper::OnPrefChange(nullptr, nullptr);
49
50 RunOnShutdown(
51 [&] {
52 DebugOnly<nsresult> rv = gQueryStringStripper->Shutdown();
53 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),do { if (!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1
))))) { NS_DebugBreak(NS_DEBUG_WARNING, "URLQueryStringStripper::Shutdown failed"
, "NS_SUCCEEDED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 54); } } while (false)
54 "URLQueryStringStripper::Shutdown failed")do { if (!(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1
))))) { NS_DebugBreak(NS_DEBUG_WARNING, "URLQueryStringStripper::Shutdown failed"
, "NS_SUCCEEDED(rv)", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 54); } } while (false)
;
55 gQueryStringStripper = nullptr;
56 },
57 ShutdownPhase::XPCOMShutdown);
58 }
59
60 return do_AddRef(gQueryStringStripper);
61}
62
63URLQueryStringStripper::URLQueryStringStripper() {
64 mIsInitialized = false;
65
66 nsresult rv = Preferences::RegisterCallback(
67 &URLQueryStringStripper::OnPrefChange, kQueryStrippingEnabledPBMPref);
68 NS_ENSURE_SUCCESS_VOID(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_VOID(%s) failed with "
"result 0x%" "X" "%s%s%s", "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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 68); return; } } while (false)
;
69
70 rv = Preferences::RegisterCallback(&URLQueryStringStripper::OnPrefChange,
Value stored to 'rv' is never read
71 kQueryStrippingEnabledPref);
72
73 rv = Preferences::RegisterCallback(&URLQueryStringStripper::OnPrefChange,
74 kQueryStrippingOnShareEnabledPref);
75 NS_ENSURE_SUCCESS_VOID(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_VOID(%s) failed with "
"result 0x%" "X" "%s%s%s", "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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 75); return; } } while (false)
;
76}
77
78NS_IMETHODIMPnsresult
79URLQueryStringStripper::StripForCopyOrShare(nsIURI* aURI,
80 nsIURI** strippedURI) {
81 NS_ENSURE_ARG_POINTER(aURI)do { if ((__builtin_expect(!!(!(aURI)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aURI" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 81); return NS_ERROR_INVALID_POINTER; } } while (false)
;
82 NS_ENSURE_ARG_POINTER(strippedURI)do { if ((__builtin_expect(!!(!(strippedURI)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "strippedURI" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 82); return NS_ERROR_INVALID_POINTER; } } while (false)
;
83 int aStripCount = 0;
84
85 nsresult rv = StripForCopyOrShareInternal(aURI, strippedURI, aStripCount,
86 /* aDry = */ false,
87 /* aStripNestedURIs = */ false);
88 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 88); return rv; } } while (false)
;
89
90 Telemetry::Accumulate(Telemetry::STRIP_ON_SHARE_PARAMS_REMOVED, aStripCount);
91
92 if (!aStripCount) {
93 return NS_OK;
94 }
95
96 // To calculate difference in length of the URL
97 // after stripping occurs for Telemetry
98 nsAutoCString specOriginalURI;
99 nsAutoCString specStrippedURI;
100
101 rv = aURI->GetDisplaySpec(specOriginalURI);
102 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 102); return rv; } } while (false)
;
103
104 MOZ_ASSERT(*strippedURI)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(*strippedURI)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(*strippedURI))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("*strippedURI", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 104); AnnotateMozCrashReason("MOZ_ASSERT" "(" "*strippedURI"
")"); do { *((volatile int*)__null) = 104; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
105
106 rv = (*strippedURI)->GetDisplaySpec(specStrippedURI);
107 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 107); return rv; } } while (false)
;
108
109 uint32_t lengthDiff = specOriginalURI.Length() - specStrippedURI.Length();
110 Telemetry::Accumulate(Telemetry::STRIP_ON_SHARE_LENGTH_DECREASE, lengthDiff);
111
112 return NS_OK;
113}
114
115NS_IMETHODIMPnsresult
116URLQueryStringStripper::CanStripForShare(nsIURI* aURI, bool* aCanStrip) {
117 NS_ENSURE_ARG_POINTER(aURI)do { if ((__builtin_expect(!!(!(aURI)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aURI" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 117); return NS_ERROR_INVALID_POINTER; } } while (false)
;
118 NS_ENSURE_ARG_POINTER(aCanStrip)do { if ((__builtin_expect(!!(!(aCanStrip)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aCanStrip" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 118); return NS_ERROR_INVALID_POINTER; } } while (false)
;
119
120 *aCanStrip = false;
121 int aStripCount = 0;
122 nsresult rv =
123 StripForCopyOrShareInternal(aURI, nullptr, aStripCount, /* aDry = */ true,
124 /* aStripNestedURIs = */ false);
125 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 125); return rv; } } while (false)
;
126
127 *aCanStrip = aStripCount != 0;
128 return NS_OK;
129}
130
131NS_IMETHODIMPnsresult
132URLQueryStringStripper::Strip(nsIURI* aURI, bool aIsPBM, nsIURI** aOutput,
133 uint32_t* aStripCount) {
134 NS_ENSURE_ARG_POINTER(aURI)do { if ((__builtin_expect(!!(!(aURI)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aURI" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 134); return NS_ERROR_INVALID_POINTER; } } while (false)
;
135 NS_ENSURE_ARG_POINTER(aOutput)do { if ((__builtin_expect(!!(!(aOutput)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aOutput" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 135); return NS_ERROR_INVALID_POINTER; } } while (false)
;
136 NS_ENSURE_ARG_POINTER(aStripCount)do { if ((__builtin_expect(!!(!(aStripCount)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aStripCount" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 136); return NS_ERROR_INVALID_POINTER; } } while (false)
;
137
138 *aStripCount = 0;
139
140 if (aIsPBM) {
141 if (!StaticPrefs::privacy_query_stripping_enabled_pbmode()) {
142 return NS_OK;
143 }
144 } else {
145 if (!StaticPrefs::privacy_query_stripping_enabled()) {
146 return NS_OK;
147 }
148 }
149
150 if (CheckAllowList(aURI)) {
151 return NS_OK;
152 }
153
154 return StripQueryString(aURI, aOutput, aStripCount);
155}
156
157// static
158void URLQueryStringStripper::OnPrefChange(const char* aPref, void* aData) {
159 MOZ_ASSERT(gQueryStringStripper)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gQueryStringStripper)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(gQueryStringStripper))), 0))
) { do { } while (false); MOZ_ReportAssertionFailure("gQueryStringStripper"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 159); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gQueryStringStripper"
")"); do { *((volatile int*)__null) = 159; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
160
161 bool prefEnablesComponent =
162 StaticPrefs::privacy_query_stripping_enabled() ||
163 StaticPrefs::privacy_query_stripping_enabled_pbmode() ||
164 StaticPrefs::privacy_query_stripping_strip_on_share_enabled();
165
166 nsresult rv;
167 if (prefEnablesComponent) {
168 rv = gQueryStringStripper->Init();
169 } else {
170 rv = gQueryStringStripper->Shutdown();
171 }
172 NS_ENSURE_SUCCESS_VOID(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_VOID(%s) failed with "
"result 0x%" "X" "%s%s%s", "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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 172); return; } } while (false)
;
173}
174
175nsresult URLQueryStringStripper::Init() {
176 nsresult rv;
177 if (mIsInitialized) {
178 rv = gQueryStringStripper->ManageObservers();
179 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 179); return rv; } } while (false)
;
180 return NS_OK;
181 }
182 mIsInitialized = true;
183
184 mListService = do_GetService("@mozilla.org/query-stripping-list-service;1");
185 NS_ENSURE_TRUE(mListService, NS_ERROR_FAILURE)do { if ((__builtin_expect(!!(!(mListService)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "mListService" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 185); return NS_ERROR_FAILURE; } } while (false)
;
186 rv = gQueryStringStripper->ManageObservers();
187 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 187); return rv; } } while (false)
;
188 return NS_OK;
189}
190
191// (Un)registers a QPS/Strip-on-share observer according to the QPS prefs states
192// and the strip-on-share pref state. This is called whenever one of the three
193// prefs changes, to ensure that we are not observing one of the lists although
194// the corresponding feature is not turned on.
195nsresult URLQueryStringStripper::ManageObservers() {
196 MOZ_ASSERT(mListService)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mListService)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mListService))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("mListService", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 196); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mListService"
")"); do { *((volatile int*)__null) = 196; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
197 nsresult rv;
198 // Register QPS observer.
199 // We are not listening to QPS but the feature is on, register a listener.
200 if (!mObservingQPS) {
201 if (StaticPrefs::privacy_query_stripping_enabled() ||
202 StaticPrefs::privacy_query_stripping_enabled_pbmode()) {
203 rv = mListService->RegisterAndRunObserver(gQueryStringStripper);
204 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 204); return rv; } } while (false)
;
205 mObservingQPS = true;
206 }
207 } else {
208 // Unregister QPS observer.
209 // We are listening to QPS but the feature is off, unregister.
210 if (!StaticPrefs::privacy_query_stripping_enabled() &&
211 !StaticPrefs::privacy_query_stripping_enabled_pbmode()) {
212 // Clean up QPS lists.
213 mList.Clear();
214 mAllowList.Clear();
215 rv = mListService->UnregisterObserver(this);
216 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 216); return rv; } } while (false)
;
217 mObservingQPS = false;
218 }
219 }
220
221 // Register Strip on Share observer.
222 // We are not listening to strip-on-share but the feature is on, register an
223 // Observer.
224 if (!mObservingStripOnShare) {
225 if (StaticPrefs::privacy_query_stripping_strip_on_share_enabled()) {
226 rv = mListService->RegisterAndRunObserverStripOnShare(
227 gQueryStringStripper);
228 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 228); return rv; } } while (false)
;
229 mObservingStripOnShare = true;
230 }
231 } else {
232 // Unregister Strip on Share observer.
233 // We are listening to strip-on-share but the feature is off, unregister.
234 if (!StaticPrefs::privacy_query_stripping_strip_on_share_enabled()) {
235 // Clean up strip-on-share list
236 mStripOnShareMap.Clear();
237 rv = mListService->UnregisterStripOnShareObserver(this);
238 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 238); return rv; } } while (false)
;
239 mObservingStripOnShare = false;
240 }
241 }
242 return NS_OK;
243}
244
245nsresult URLQueryStringStripper::Shutdown() {
246 if (!mIsInitialized) {
247 return NS_OK;
248 }
249 nsresult rv = gQueryStringStripper->ManageObservers();
250 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 250); return rv; } } while (false)
;
251 mIsInitialized = false;
252 mListService = nullptr;
253 return NS_OK;
254}
255
256nsresult URLQueryStringStripper::StripQueryString(nsIURI* aURI,
257 nsIURI** aOutput,
258 uint32_t* aStripCount) {
259 NS_ENSURE_ARG_POINTER(aURI)do { if ((__builtin_expect(!!(!(aURI)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aURI" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 259); return NS_ERROR_INVALID_POINTER; } } while (false)
;
260 NS_ENSURE_ARG_POINTER(aOutput)do { if ((__builtin_expect(!!(!(aOutput)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aOutput" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 260); return NS_ERROR_INVALID_POINTER; } } while (false)
;
261 NS_ENSURE_ARG_POINTER(aStripCount)do { if ((__builtin_expect(!!(!(aStripCount)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aStripCount" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 261); return NS_ERROR_INVALID_POINTER; } } while (false)
;
262
263 *aStripCount = 0;
264
265 nsCOMPtr<nsIURI> uri(aURI);
266
267 nsAutoCString query;
268 nsresult rv = aURI->GetQuery(query);
269 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 269); return rv; } } while (false)
;
270
271 // We don't need to do anything if there is no query string.
272 if (query.IsEmpty()) {
273 return NS_OK;
274 }
275
276 URLParams params;
277
278 URLParams::Parse(query, false, [&](nsCString&& name, nsCString&& value) {
279 nsAutoCString lowerCaseName;
280 ToLowerCase(name, lowerCaseName);
281
282 if (mList.Contains(lowerCaseName)) {
283 *aStripCount += 1;
284
285 // Count how often a specific query param is stripped. For privacy reasons
286 // this will only count query params listed in the Histogram definition.
287 // Calls for any other query params will be discarded.
288 nsAutoCString telemetryLabel("param_");
289 telemetryLabel.Append(lowerCaseName);
290 Telemetry::AccumulateCategorical(
291 Telemetry::QUERY_STRIPPING_COUNT_BY_PARAM, telemetryLabel);
292
293 return true;
294 }
295
296 params.Append(name, value);
297 return true;
298 });
299
300 // Return if there is no parameter has been stripped.
301 if (!*aStripCount) {
302 return NS_OK;
303 }
304
305 nsAutoCString newQuery;
306 params.Serialize(newQuery, false);
307
308 Unused << NS_MutateURI(uri).SetQuery(newQuery).Finalize(aOutput);
309 return NS_OK;
310}
311
312bool URLQueryStringStripper::CheckAllowList(nsIURI* aURI) {
313 MOZ_ASSERT(aURI)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aURI)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!(aURI))), 0))) { do { } while (false
); MOZ_ReportAssertionFailure("aURI", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 313); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aURI" ")"); do
{ *((volatile int*)__null) = 313; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
314
315 // Get the site(eTLD+1) from the URI.
316 nsAutoCString baseDomain;
317 nsresult rv =
318 nsEffectiveTLDService::GetInstance()->GetBaseDomain(aURI, 0, baseDomain);
319 if (rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
320 rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
321 return false;
322 }
323 NS_ENSURE_SUCCESS(rv, false)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", "false", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 323); return false; } } while (false)
;
324
325 return mAllowList.Contains(baseDomain);
326}
327
328void URLQueryStringStripper::PopulateStripList(const nsACString& aList) {
329 mList.Clear();
330
331 for (const nsACString& item : aList.Split(' ')) {
332 mList.Insert(item);
333 }
334}
335
336void URLQueryStringStripper::PopulateAllowList(const nsACString& aList) {
337 mAllowList.Clear();
338
339 for (const nsACString& item : aList.Split(',')) {
340 mAllowList.Insert(item);
341 }
342}
343
344NS_IMETHODIMPnsresult
345URLQueryStringStripper::OnQueryStrippingListUpdate(
346 const nsACString& aStripList, const nsACString& aAllowList) {
347 PopulateStripList(aStripList);
348 PopulateAllowList(aAllowList);
349 return NS_OK;
350}
351
352NS_IMETHODIMPnsresult
353URLQueryStringStripper::OnStripOnShareUpdate(const nsTArray<nsString>& aArgs,
354 JSContext* aCx) {
355 for (const auto& ruleString : aArgs) {
356 dom::StripRule rule;
357 if (NS_WARN_IF(!rule.Init(ruleString))NS_warn_if_impl(!rule.Init(ruleString), "!rule.Init(ruleString)"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 357)
) {
358 // Skipping malformed rules
359 continue;
360 }
361 for (const auto& topLevelSite : rule.mTopLevelSites) {
362 mStripOnShareMap.InsertOrUpdate(topLevelSite, rule);
363 }
364 }
365 return NS_OK;
366}
367// static
368NS_IMETHODIMPnsresult
369URLQueryStringStripper::TestGetStripList(nsACString& aStripList) {
370 aStripList.Truncate();
371
372 StringJoinAppend(
373 aStripList, " "_ns, mList,
374 [](auto& aResult, const auto& aValue) { aResult.Append(aValue); });
375 return NS_OK;
376}
377
378/* nsIObserver */
379NS_IMETHODIMPnsresult
380URLQueryStringStripper::Observe(nsISupports*, const char* aTopic,
381 const char16_t*) {
382 // Since this class is created at profile-after-change by the Category
383 // Manager, it's expected to implement nsIObserver; however, we have nothing
384 // interesting to do here.
385 MOZ_ASSERT(strcmp(aTopic, "profile-after-change") == 0)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(strcmp(aTopic, "profile-after-change") == 0)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(strcmp(aTopic, "profile-after-change") == 0))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("strcmp(aTopic, \"profile-after-change\") == 0"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 385); AnnotateMozCrashReason("MOZ_ASSERT" "(" "strcmp(aTopic, \"profile-after-change\") == 0"
")"); do { *((volatile int*)__null) = 385; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
386
387 return NS_OK;
388}
389
390bool URLQueryStringStripper::ShouldStripParam(const nsACString& aHost,
391 const nsACString& aName) {
392 nsAutoCString lowerCaseName;
393 ToLowerCase(aName, lowerCaseName);
394
395 // Look through the global rules.
396 dom::StripRule globalRule;
397 bool keyExists = mStripOnShareMap.Get("*"_ns, &globalRule);
398 // There should always be a global rule.
399 MOZ_ASSERT(keyExists)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(keyExists)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(keyExists))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("keyExists", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 399); AnnotateMozCrashReason("MOZ_ASSERT" "(" "keyExists" ")"
); do { *((volatile int*)__null) = 399; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
400
401 // Look through the global rules.
402 for (const auto& param : globalRule.mQueryParams) {
403 if (param == lowerCaseName) {
404 return true;
405 }
406 }
407
408 // Check for site specific rules.
409 dom::StripRule siteSpecificRule;
410 keyExists = mStripOnShareMap.Get(aHost, &siteSpecificRule);
411 if (keyExists) {
412 for (const auto& param : siteSpecificRule.mQueryParams) {
413 if (param == lowerCaseName) {
414 return true;
415 }
416 }
417 }
418
419 // no rule covering
420 return false;
421}
422
423int URLQueryStringStripper::TryStripValue(const nsACString& aHost,
424 nsACString& aValue, bool aDry) {
425 nsresult rv;
426
427 nsAutoCString decodeValue;
428 URLParams::DecodeString(aValue, decodeValue);
429
430 nsCOMPtr<nsIURI> nestedURI;
431 rv = NS_NewURI(getter_AddRefs(nestedURI), decodeValue);
432
433 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
434 return 0;
435 }
436
437 int stripCount = 0;
438 // recurse down
439 nsCOMPtr<nsIURI> strippedNestedURI;
440 rv = StripForCopyOrShareInternal(nestedURI, getter_AddRefs(strippedNestedURI),
441 stripCount, aDry,
442 /* aStripNestedURIs = */ true);
443
444 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && stripCount != 0) {
445 if (aDry) {
446 return 1;
447 }
448 MOZ_ASSERT(strippedNestedURI,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(strippedNestedURI)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(strippedNestedURI))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("strippedNestedURI"
" (" "URL must be returned if stripCount != 0 in non-dry mode"
")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 449); AnnotateMozCrashReason("MOZ_ASSERT" "(" "strippedNestedURI"
") (" "URL must be returned if stripCount != 0 in non-dry mode"
")"); do { *((volatile int*)__null) = 449; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
449 "URL must be returned if stripCount != 0 in non-dry mode")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(strippedNestedURI)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(strippedNestedURI))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("strippedNestedURI"
" (" "URL must be returned if stripCount != 0 in non-dry mode"
")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 449); AnnotateMozCrashReason("MOZ_ASSERT" "(" "strippedNestedURI"
") (" "URL must be returned if stripCount != 0 in non-dry mode"
")"); do { *((volatile int*)__null) = 449; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
450 nsAutoCString nestedURIString;
451 rv = strippedNestedURI->GetSpec(nestedURIString);
452 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 452)
) {
453 return 0;
454 }
455
456 // Overwrite aValue with URL with stripped query parameters
457 aValue.Truncate();
458 URLParams::SerializeString(nestedURIString, aValue);
459 return stripCount;
460 }
461 return 0;
462}
463
464nsresult URLQueryStringStripper::StripForCopyOrShareInternal(
465 nsIURI* aURI, nsIURI** aStrippedURI, int& aStripCount, bool aDry,
466 bool aStripNestedURIs) {
467 nsAutoCString query;
468 nsresult rv = aURI->GetQuery(query);
469 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 469); return rv; } } while (false)
;
470
471 // We don't need to do anything if there is no query string.
472 if (query.IsEmpty()) {
473 return NS_OK;
474 }
475
476 nsAutoCString host;
477 rv = aURI->GetHost(host);
478 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/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 478); return rv; } } while (false)
;
479
480 URLParams params;
481
482 URLParams::Parse(query, false, [&](nsCString&& aName, nsCString&& aValue) {
483 if (ShouldStripParam(host, aName)) {
484 aStripCount++;
485 // If we found a query param to strip in dry mode, skip iterating over the
486 // remaining ones (we return greedily). Otherwise don't add the param to
487 // the new list and continue with the next one.
488 return !aDry;
489 }
490
491 // Only if it is top layer of the recursion then it checks if the value of
492 // the query parameter is a valid URI if not then it gets added back to the
493 // query, if it is then it gets passed back into this method but with the
494 // recursive stripping flag set to true
495 if (!aStripNestedURIs) {
496 aStripCount += TryStripValue(host, aValue, aDry);
497 }
498 if (aDry) {
499 return aStripCount == 0;
500 }
501
502 params.Append(aName, aValue);
503 return true;
504 });
505
506 // Returns null for aStrippedURI if no query params have been stripped
507 // or in dry mode.
508 if (!aStripCount || aDry || !aStrippedURI) {
509 return NS_OK;
510 }
511
512 nsAutoCString newQuery;
513 params.Serialize(newQuery, false);
514 return NS_MutateURI(aURI).SetQuery(newQuery).Finalize(aStrippedURI);
515}
516} // namespace mozilla