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 |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | |
23 | namespace { |
24 | |
25 | mozilla::StaticRefPtr<mozilla::URLQueryStringStripper> gQueryStringStripper; |
26 | |
27 | static const char kQueryStrippingEnabledPref[] = |
28 | "privacy.query_stripping.enabled"; |
29 | static const char kQueryStrippingEnabledPBMPref[] = |
30 | "privacy.query_stripping.enabled.pbmode"; |
31 | static const char kQueryStrippingOnShareEnabledPref[] = |
32 | "privacy.query_stripping.strip_on_share.enabled"; |
33 | |
34 | } // namespace |
35 | |
36 | namespace mozilla { |
37 | |
38 | NS_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 |
42 | already_AddRefed<URLQueryStringStripper> |
43 | URLQueryStringStripper::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 | |
63 | URLQueryStringStripper::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 | |
78 | NS_IMETHODIMPnsresult |
79 | URLQueryStringStripper::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 | |
117 | NS_IMETHODIMPnsresult |
118 | URLQueryStringStripper::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 |
144 | void 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 | |
161 | nsresult 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. |
181 | nsresult 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 | |
231 | nsresult 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 | |
242 | nsresult 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 | |
298 | bool 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 | |
314 | void URLQueryStringStripper::PopulateStripList(const nsACString& aList) { |
315 | mList.Clear(); |
316 | |
317 | for (const nsACString& item : aList.Split(' ')) { |
318 | mList.Insert(item); |
319 | } |
320 | } |
321 | |
322 | void URLQueryStringStripper::PopulateAllowList(const nsACString& aList) { |
323 | mAllowList.Clear(); |
324 | |
325 | for (const nsACString& item : aList.Split(',')) { |
326 | mAllowList.Insert(item); |
327 | } |
328 | } |
329 | |
330 | NS_IMETHODIMPnsresult |
331 | URLQueryStringStripper::OnQueryStrippingListUpdate( |
332 | const nsACString& aStripList, const nsACString& aAllowList) { |
333 | PopulateStripList(aStripList); |
334 | PopulateAllowList(aAllowList); |
335 | return NS_OK; |
336 | } |
337 | |
338 | NS_IMETHODIMPnsresult |
339 | URLQueryStringStripper::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 |
354 | NS_IMETHODIMPnsresult |
355 | URLQueryStringStripper::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 */ |
365 | NS_IMETHODIMPnsresult |
366 | URLQueryStringStripper::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 | |
376 | nsresult 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 | params.Append(name, value); |
447 | return true; |
448 | } |
449 | |
450 | if (!strippedNestedURI) { |
451 | params.Append(name, value); |
452 | return true; |
453 | } |
454 | |
455 | nsAutoCString nestedURIString; |
456 | rv = strippedNestedURI->GetSpec(nestedURIString); |
457 | 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" , 457)) { |
458 | params.Append(name, value); |
459 | return true; |
460 | } |
461 | |
462 | // Encodes URI |
463 | nsAutoCString encodedURI; |
464 | URLParams::SerializeString(nestedURIString, encodedURI); |
465 | |
466 | params.Append(name, encodedURI); |
467 | return true; |
468 | } |
469 | |
470 | params.Append(name, value); |
471 | return true; |
472 | }); |
473 | |
474 | // Returns null for strippedURI if no query params have been stripped. |
475 | if (!aStripCount) { |
476 | return NS_OK; |
477 | } |
478 | |
479 | nsAutoCString newQuery; |
480 | params.Serialize(newQuery, false); |
481 | return NS_MutateURI(aURI).SetQuery(newQuery).Finalize(strippedURI); |
482 | } |
483 | |
484 | } // namespace mozilla |