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_antitracking0.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-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 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/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-05-16-034744-15991-1 -x c++ Unified_cpp_antitracking0.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((sizeof(table) /
sizeof(table[0])) > 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((sizeof(table) /
sizeof(table[0])) > 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 if (!StaticPrefs::privacy_query_stripping_strip_on_share_enabled()) {
82 return NS_ERROR_NOT_AVAILABLE;
83 }
84 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"
, 84); return NS_ERROR_INVALID_POINTER; } } while (false)
;
85 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"
, 85); return NS_ERROR_INVALID_POINTER; } } while (false)
;
86 int aStripCount = 0;
87
88 nsresult rv =
89 StripForCopyOrShareInternal(aURI, strippedURI, aStripCount, false);
90 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"
, 90); return rv; } } while (false)
;
91
92 Telemetry::Accumulate(Telemetry::STRIP_ON_SHARE_PARAMS_REMOVED, aStripCount);
93
94 if (!aStripCount) {
95 return NS_OK;
96 }
97
98 // To calculate difference in length of the URL
99 // after stripping occurs for Telemetry
100 nsAutoCString specOriginalURI;
101 nsAutoCString specStrippedURI;
102
103 rv = aURI->GetDisplaySpec(specOriginalURI);
104 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"
, 104); return rv; } } while (false)
;
105
106 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"
, 106); AnnotateMozCrashReason("MOZ_ASSERT" "(" "*strippedURI"
")"); do { *((volatile int*)__null) = 106; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
107
108 rv = (*strippedURI)->GetDisplaySpec(specStrippedURI);
109 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"
, 109); return rv; } } while (false)
;
110
111 uint32_t lengthDiff = specOriginalURI.Length() - specStrippedURI.Length();
112 Telemetry::Accumulate(Telemetry::STRIP_ON_SHARE_LENGTH_DECREASE, lengthDiff);
113
114 return NS_OK;
115}
116
117NS_IMETHODIMPnsresult
118URLQueryStringStripper::Strip(nsIURI* aURI, bool aIsPBM, nsIURI** aOutput,
119 uint32_t* aStripCount) {
120 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"
, 120); return NS_ERROR_INVALID_POINTER; } } while (false)
;
121 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"
, 121); return NS_ERROR_INVALID_POINTER; } } while (false)
;
122 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"
, 122); return NS_ERROR_INVALID_POINTER; } } while (false)
;
123
124 *aStripCount = 0;
125
126 if (aIsPBM) {
127 if (!StaticPrefs::privacy_query_stripping_enabled_pbmode()) {
128 return NS_OK;
129 }
130 } else {
131 if (!StaticPrefs::privacy_query_stripping_enabled()) {
132 return NS_OK;
133 }
134 }
135
136 if (CheckAllowList(aURI)) {
137 return NS_OK;
138 }
139
140 return StripQueryString(aURI, aOutput, aStripCount);
141}
142
143// static
144void URLQueryStringStripper::OnPrefChange(const char* aPref, void* aData) {
145 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"
, 145); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gQueryStringStripper"
")"); do { *((volatile int*)__null) = 145; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
146
147 bool prefEnablesComponent =
148 StaticPrefs::privacy_query_stripping_enabled() ||
149 StaticPrefs::privacy_query_stripping_enabled_pbmode() ||
150 StaticPrefs::privacy_query_stripping_strip_on_share_enabled();
151
152 nsresult rv;
153 if (prefEnablesComponent) {
154 rv = gQueryStringStripper->Init();
155 } else {
156 rv = gQueryStringStripper->Shutdown();
157 }
158 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"
, 158); return; } } while (false)
;
159}
160
161nsresult URLQueryStringStripper::Init() {
162 nsresult rv;
163 if (mIsInitialized) {
164 rv = gQueryStringStripper->ManageObservers();
165 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"
, 165); return rv; } } while (false)
;
166 return NS_OK;
167 }
168 mIsInitialized = true;
169
170 mListService = do_GetService("@mozilla.org/query-stripping-list-service;1");
171 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"
, 171); return NS_ERROR_FAILURE; } } while (false)
;
172 rv = gQueryStringStripper->ManageObservers();
173 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"
, 173); return rv; } } while (false)
;
174 return NS_OK;
175}
176
177// (Un)registers a QPS/Strip-on-share observer according to the QPS prefs states
178// and the strip-on-share pref state. This is called whenever one of the three
179// prefs changes, to ensure that we are not observing one of the lists although
180// the corresponding feature is not turned on.
181nsresult URLQueryStringStripper::ManageObservers() {
182 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"
, 182); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mListService"
")"); do { *((volatile int*)__null) = 182; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
183 nsresult rv;
184 // Register QPS observer.
185 // We are not listening to QPS but the feature is on, register a listener.
186 if (!mObservingQPS) {
187 if (StaticPrefs::privacy_query_stripping_enabled() ||
188 StaticPrefs::privacy_query_stripping_enabled_pbmode()) {
189 rv = mListService->RegisterAndRunObserver(gQueryStringStripper);
190 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"
, 190); return rv; } } while (false)
;
191 mObservingQPS = true;
192 }
193 } else {
194 // Unregister QPS observer.
195 // We are listening to QPS but the feature is off, unregister.
196 if (!StaticPrefs::privacy_query_stripping_enabled() &&
197 !StaticPrefs::privacy_query_stripping_enabled_pbmode()) {
198 // Clean up QPS lists.
199 mList.Clear();
200 mAllowList.Clear();
201 rv = mListService->UnregisterObserver(this);
202 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"
, 202); return rv; } } while (false)
;
203 mObservingQPS = false;
204 }
205 }
206
207 // Register Strip on Share observer.
208 // We are not listening to strip-on-share but the feature is on, register an
209 // Observer.
210 if (!mObservingStripOnShare) {
211 if (StaticPrefs::privacy_query_stripping_strip_on_share_enabled()) {
212 rv = mListService->RegisterAndRunObserverStripOnShare(
213 gQueryStringStripper);
214 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"
, 214); return rv; } } while (false)
;
215 mObservingStripOnShare = true;
216 }
217 } else {
218 // Unregister Strip on Share observer.
219 // We are listening to strip-on-share but the feature is off, unregister.
220 if (!StaticPrefs::privacy_query_stripping_strip_on_share_enabled()) {
221 // Clean up strip-on-share list
222 mStripOnShareMap.Clear();
223 rv = mListService->UnregisterStripOnShareObserver(this);
224 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"
, 224); return rv; } } while (false)
;
225 mObservingStripOnShare = false;
226 }
227 }
228 return NS_OK;
229}
230
231nsresult URLQueryStringStripper::Shutdown() {
232 if (!mIsInitialized) {
233 return NS_OK;
234 }
235 nsresult rv = gQueryStringStripper->ManageObservers();
236 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"
, 236); return rv; } } while (false)
;
237 mIsInitialized = false;
238 mListService = nullptr;
239 return NS_OK;
240}
241
242nsresult URLQueryStringStripper::StripQueryString(nsIURI* aURI,
243 nsIURI** aOutput,
244 uint32_t* aStripCount) {
245 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"
, 245); return NS_ERROR_INVALID_POINTER; } } while (false)
;
246 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"
, 246); return NS_ERROR_INVALID_POINTER; } } while (false)
;
247 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"
, 247); return NS_ERROR_INVALID_POINTER; } } while (false)
;
248
249 *aStripCount = 0;
250
251 nsCOMPtr<nsIURI> uri(aURI);
252
253 nsAutoCString query;
254 nsresult rv = aURI->GetQuery(query);
255 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"
, 255); return rv; } } while (false)
;
256
257 // We don't need to do anything if there is no query string.
258 if (query.IsEmpty()) {
259 return NS_OK;
260 }
261
262 URLParams params;
263
264 URLParams::Parse(query, false, [&](nsCString&& name, nsCString&& value) {
265 nsAutoCString lowerCaseName;
266 ToLowerCase(name, lowerCaseName);
267
268 if (mList.Contains(lowerCaseName)) {
269 *aStripCount += 1;
270
271 // Count how often a specific query param is stripped. For privacy reasons
272 // this will only count query params listed in the Histogram definition.
273 // Calls for any other query params will be discarded.
274 nsAutoCString telemetryLabel("param_");
275 telemetryLabel.Append(lowerCaseName);
276 Telemetry::AccumulateCategorical(
277 Telemetry::QUERY_STRIPPING_COUNT_BY_PARAM, telemetryLabel);
278
279 return true;
280 }
281
282 params.Append(name, value);
283 return true;
284 });
285
286 // Return if there is no parameter has been stripped.
287 if (!*aStripCount) {
288 return NS_OK;
289 }
290
291 nsAutoCString newQuery;
292 params.Serialize(newQuery, false);
293
294 Unused << NS_MutateURI(uri).SetQuery(newQuery).Finalize(aOutput);
295 return NS_OK;
296}
297
298bool URLQueryStringStripper::CheckAllowList(nsIURI* aURI) {
299 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"
, 299); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aURI" ")"); do
{ *((volatile int*)__null) = 299; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
300
301 // Get the site(eTLD+1) from the URI.
302 nsAutoCString baseDomain;
303 nsresult rv =
304 nsEffectiveTLDService::GetInstance()->GetBaseDomain(aURI, 0, baseDomain);
305 if (rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
306 rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
307 return false;
308 }
309 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"
, 309); return false; } } while (false)
;
310
311 return mAllowList.Contains(baseDomain);
312}
313
314void URLQueryStringStripper::PopulateStripList(const nsACString& aList) {
315 mList.Clear();
316
317 for (const nsACString& item : aList.Split(' ')) {
318 mList.Insert(item);
319 }
320}
321
322void URLQueryStringStripper::PopulateAllowList(const nsACString& aList) {
323 mAllowList.Clear();
324
325 for (const nsACString& item : aList.Split(',')) {
326 mAllowList.Insert(item);
327 }
328}
329
330NS_IMETHODIMPnsresult
331URLQueryStringStripper::OnQueryStrippingListUpdate(
332 const nsACString& aStripList, const nsACString& aAllowList) {
333 PopulateStripList(aStripList);
334 PopulateAllowList(aAllowList);
335 return NS_OK;
336}
337
338NS_IMETHODIMPnsresult
339URLQueryStringStripper::OnStripOnShareUpdate(const nsTArray<nsString>& aArgs,
340 JSContext* aCx) {
341 for (const auto& ruleString : aArgs) {
342 dom::StripRule rule;
343 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"
, 343)
) {
344 // Skipping malformed rules
345 continue;
346 }
347 for (const auto& topLevelSite : rule.mTopLevelSites) {
348 mStripOnShareMap.InsertOrUpdate(topLevelSite, rule);
349 }
350 }
351 return NS_OK;
352}
353// static
354NS_IMETHODIMPnsresult
355URLQueryStringStripper::TestGetStripList(nsACString& aStripList) {
356 aStripList.Truncate();
357
358 StringJoinAppend(
359 aStripList, " "_ns, mList,
360 [](auto& aResult, const auto& aValue) { aResult.Append(aValue); });
361 return NS_OK;
362}
363
364/* nsIObserver */
365NS_IMETHODIMPnsresult
366URLQueryStringStripper::Observe(nsISupports*, const char* aTopic,
367 const char16_t*) {
368 // Since this class is created at profile-after-change by the Category
369 // Manager, it's expected to implement nsIObserver; however, we have nothing
370 // interesting to do here.
371 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"
, 371); AnnotateMozCrashReason("MOZ_ASSERT" "(" "strcmp(aTopic, \"profile-after-change\") == 0"
")"); do { *((volatile int*)__null) = 371; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
372
373 return NS_OK;
374}
375
376nsresult URLQueryStringStripper::StripForCopyOrShareInternal(
377 nsIURI* aURI, nsIURI** strippedURI, int& aStripCount,
378 bool aStripNestedURIs) {
379 nsAutoCString query;
380 nsresult rv = aURI->GetQuery(query);
381 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"
, 381); return rv; } } while (false)
;
382
383 // We don't need to do anything if there is no query string.
384 if (query.IsEmpty()) {
385 Telemetry::Accumulate(Telemetry::STRIP_ON_SHARE_PARAMS_REMOVED, 0);
386 return NS_OK;
387 }
388
389 nsAutoCString host;
390 rv = aURI->GetHost(host);
391 NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl
(__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName
(__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with "
"result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t
>(__rv), name ? " (" : "", name ? name : "", name ? ")" : ""
); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLQueryStringStripper.cpp"
, 391); return rv; } } while (false)
;
392
393 URLParams params;
394
395 URLParams::Parse(query, false, [&](nsCString&& name, nsCString&& value) {
396 nsAutoCString lowerCaseName;
397 ToLowerCase(name, lowerCaseName);
398
399 // Look through the global rules.
400 dom::StripRule globalRule;
401 bool keyExists = mStripOnShareMap.Get("*"_ns, &globalRule);
402 // There should always be a global rule.
403 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"
, 403); AnnotateMozCrashReason("MOZ_ASSERT" "(" "keyExists" ")"
); do { *((volatile int*)__null) = 403; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
404
405 // Look through the global rules.
406 for (const auto& param : globalRule.mQueryParams) {
407 if (param == lowerCaseName) {
408 aStripCount++;
409 return true;
410 }
411 }
412
413 // Check for site specific rules.
414 dom::StripRule siteSpecificRule;
415 keyExists = mStripOnShareMap.Get(host, &siteSpecificRule);
416 if (keyExists) {
417 for (const auto& param : siteSpecificRule.mQueryParams) {
418 if (param == lowerCaseName) {
419 aStripCount++;
420 return true;
421 }
422 }
423 }
424
425 // Only if it is top layer of the recursion then it
426 // checks if the value of the query parameter is a valid URI
427 // if not then it gets added back to the query, if it is then
428 // it gets passed back into this method but with the recursive
429 // stripping flag set to true
430 if (!aStripNestedURIs) {
431 nsAutoCString decodeValue;
432 URLParams::DecodeString(value, decodeValue);
433
434 nsCOMPtr<nsIURI> nestedURI;
435 rv = NS_NewURI(getter_AddRefs(nestedURI), decodeValue);
436
437 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"
, 437)
) {
438 params.Append(name, value);
439 return true;
440 }
441
442 nsCOMPtr<nsIURI> strippedNestedURI;
443 rv = StripForCopyOrShareInternal(
444 nestedURI, getter_AddRefs(strippedNestedURI), aStripCount, true);
445 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"
, 445)
) {
446 return false;
447 }
448
449 if (!strippedNestedURI) {
450 params.Append(name, value);
451 return true;
452 }
453
454 nsAutoCString nestedURIString;
455 rv = strippedNestedURI->GetSpec(nestedURIString);
456 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"
, 456)
) {
457 return false;
458 }
459
460 // Encodes URI
461 nsAutoCString encodedURI;
462 URLParams::SerializeString(nestedURIString, encodedURI);
463
464 params.Append(name, encodedURI);
465 return true;
466 }
467
468 params.Append(name, value);
469 return true;
470 });
471
472 // Returns null for strippedURI if no query params have been stripped.
473 if (!aStripCount) {
474 return NS_OK;
475 }
476
477 nsAutoCString newQuery;
478 params.Serialize(newQuery, false);
479 return NS_MutateURI(aURI).SetQuery(newQuery).Finalize(strippedURI);
480}
481
482} // namespace mozilla