Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLDecorationStripper.cpp
Warning:line 26, column 12
Value stored to 'rv' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_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/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#include "URLDecorationStripper.h"
8
9#include "mozilla/Preferences.h"
10#include "nsCharSeparatedTokenizer.h"
11#include "nsEffectiveTLDService.h"
12#include "nsIURI.h"
13#include "nsIURIMutator.h"
14#include "nsURLHelper.h"
15
16namespace {
17static const char* kPrefName =
18 "privacy.restrict3rdpartystorage.url_decorations";
19} // namespace
20
21namespace mozilla {
22
23nsresult URLDecorationStripper::StripTrackingIdentifiers(nsIURI* aURI,
24 nsACString& aOutSpec) {
25 nsAutoCString tokenList;
26 nsresult rv = Preferences::GetCString(kPrefName, tokenList);
Value stored to 'rv' during its initialization is never read
27 ToLowerCase(tokenList);
28
29 nsAutoCString path;
30 rv = aURI->GetPathQueryRef(path);
31 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/URLDecorationStripper.cpp"
, 31); return rv; } } while (false)
;
32 ToLowerCase(path);
33
34 int32_t queryBegins = path.FindChar('?');
35 // Only positive values are valid since the path must begin with a '/'.
36 if (queryBegins > 0) {
37 for (const nsACString& token : tokenList.Split(' ')) {
38 if (token.IsEmpty()) {
39 continue;
40 }
41
42 nsAutoCString value;
43 if (URLParams::Extract(Substring(path, queryBegins + 1), token, value) &&
44 !value.IsVoid()) {
45 // Tracking identifier found in the URL!
46 return StripToRegistrableDomain(aURI, aOutSpec);
47 }
48 }
49 }
50
51 return aURI->GetSpec(aOutSpec);
52}
53
54nsresult URLDecorationStripper::StripToRegistrableDomain(nsIURI* aURI,
55 nsACString& aOutSpec) {
56 NS_MutateURI mutator(aURI);
57 mutator.SetPathQueryRef(""_ns).SetUserPass(""_ns);
58
59 RefPtr<nsEffectiveTLDService> etldService =
60 nsEffectiveTLDService::GetInstance();
61 NS_ENSURE_TRUE(etldService, NS_ERROR_FAILURE)do { if ((__builtin_expect(!!(!(etldService)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "etldService" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/antitracking/URLDecorationStripper.cpp"
, 61); return NS_ERROR_FAILURE; } } while (false)
;
62 nsAutoCString baseDomain;
63 nsresult rv = etldService->GetBaseDomain(aURI, 0, baseDomain);
64 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
65 mutator.SetHost(baseDomain);
66 } else {
67 // If this is an IP address or something like "localhost", ignore the error.
68 if (rv != NS_ERROR_HOST_IS_IP_ADDRESS &&
69 rv != NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
70 return rv;
71 }
72 }
73
74 nsCOMPtr<nsIURI> uri;
75 rv = mutator.Finalize(uri);
76 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/URLDecorationStripper.cpp"
, 76); return rv; } } while (false)
;
77 return uri->GetSpec(aOutSpec);
78}
79
80} // namespace mozilla