Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp
Warning:line 258, column 7
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_toolkit_xre0.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/xre -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/xre -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 TELEMETRY_PING_FORMAT_VERSION=4 -D PROXY_PRINTING=1 -D USE_GLX_TEST -D MOZ_APP_NAME="firefox" -D MOZ_APP_BASENAME="Firefox" -D MOZ_APP_DISPLAYNAME="Nightly" -D MOZ_APP_VENDOR="Mozilla" -D MOZ_APP_VERSION="130.0a1" -D OS_TARGET="Linux" -D MOZ_WIDGET_TOOLKIT="gtk" -D MOZ_UPDATER -D MOZ_DISTRIBUTION_ID="org.mozilla" -D TARGET_OS_ABI="Linux_x86_64-gcc3" -D GRE_MILESTONE=130.0a1 -D MOZ_APP_VERSION_DISPLAY=130.0a1 -D APP_VERSION=130.0a1 -D APP_ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384} -D MOZ_BUILD_APP_IS_BROWSER -D MAR_NSS -D TOPOBJDIR=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/toolkit/xre -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/remote -I /var/lib/jenkins/workspace/firefox-scan-build/widget -I /var/lib/jenkins/workspace/firefox-scan-build/widget/gtk -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/printingui -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/other-licenses/nsis/Contrib/CityHash/cityhash -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/find -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/printingui/ipc -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/components/windowwatcher -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/mozapps/update/common -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/profile -I /var/lib/jenkins/workspace/firefox-scan-build/config -I /var/lib/jenkins/workspace/firefox-scan-build/dom/base -I /var/lib/jenkins/workspace/firefox-scan-build/dom/commandhandler -I /var/lib/jenkins/workspace/firefox-scan-build/dom/ipc -I /var/lib/jenkins/workspace/firefox-scan-build/dom/webbrowserpersist -I /var/lib/jenkins/workspace/firefox-scan-build/js/xpconnect/loader -I /var/lib/jenkins/workspace/firefox-scan-build/testing/gtest/mozilla -I /var/lib/jenkins/workspace/firefox-scan-build/toolkit/crashreporter -I /var/lib/jenkins/workspace/firefox-scan-build/xpcom/build -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 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/cloudproviders -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/gtk-3.0/unix-print -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -fdeprecated-macro -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-07-27-022226-2793976-1 -x c++ Unified_cpp_toolkit_xre0.cpp
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6#include "nsAppRunner.h"
7#include "nsXREDirProvider.h"
8#ifndef ANDROID
9# include "commonupdatedir.h"
10#endif
11
12#include "jsapi.h"
13#include "xpcpublic.h"
14#include "prprf.h"
15
16#include "nsIAppStartup.h"
17#include "nsIFile.h"
18#include "nsIObserver.h"
19#include "nsIObserverService.h"
20#include "nsISimpleEnumerator.h"
21#include "nsIToolkitProfileService.h"
22#include "nsIXULRuntime.h"
23#include "commonupdatedir.h"
24
25#include "nsAppDirectoryServiceDefs.h"
26#include "nsDirectoryServiceDefs.h"
27#include "nsDirectoryServiceUtils.h"
28#include "nsXULAppAPI.h"
29#include "nsCategoryManagerUtils.h"
30
31#include "nsDependentString.h"
32#include "nsCOMArray.h"
33#include "nsArrayEnumerator.h"
34#include "nsEnumeratorUtils.h"
35#include "nsReadableUtils.h"
36
37#include "SpecialSystemDirectory.h"
38
39#include "mozilla/dom/ScriptSettings.h"
40
41#include "mozilla/AppShutdown.h"
42#include "mozilla/AutoRestore.h"
43#ifdef MOZ_BACKGROUNDTASKS1
44# include "mozilla/BackgroundTasks.h"
45#endif
46#include "mozilla/Components.h"
47#include "mozilla/Services.h"
48#include "mozilla/Omnijar.h"
49#include "mozilla/Preferences.h"
50#include "mozilla/ProfilerLabels.h"
51#include "mozilla/Telemetry.h"
52#include "mozilla/XREAppData.h"
53#include "nsPrintfCString.h"
54
55#ifdef MOZ_THUNDERBIRD
56# include "nsIPK11TokenDB.h"
57# include "nsIPK11Token.h"
58# ifdef XP_MACOSX
59# include "MacApplicationDelegate.h"
60# endif
61#endif
62
63#include <stdlib.h>
64
65#ifdef XP_WIN
66# include <windows.h>
67# include <shlobj.h>
68# include "WinUtils.h"
69#endif
70#ifdef XP_MACOSX
71# include "nsILocalFileMac.h"
72// for chflags()
73# include <sys/stat.h>
74# include <unistd.h>
75#endif
76#ifdef XP_UNIX1
77# include <ctype.h>
78#endif
79#ifdef XP_IOS
80# include "UIKitDirProvider.h"
81#endif
82
83#if defined(MOZ_CONTENT_TEMP_DIR1)
84# include "mozilla/SandboxSettings.h"
85# include "nsID.h"
86# include "mozilla/Unused.h"
87#endif
88
89#if defined(XP_MACOSX)
90# define APP_REGISTRY_NAME"appreg" "Application Registry"
91#elif defined(XP_WIN)
92# define APP_REGISTRY_NAME"appreg" "registry.dat"
93#else
94# define APP_REGISTRY_NAME"appreg" "appreg"
95#endif
96
97#define PREF_OVERRIDE_DIRNAME"preferences" "preferences"
98
99#if defined(MOZ_CONTENT_TEMP_DIR1)
100static already_AddRefed<nsIFile> GetProcessSandboxTempDir(
101 GeckoProcessType type);
102static nsresult DeleteDirIfExists(nsIFile* dir);
103static bool IsContentSandboxDisabled();
104static const char* GetProcessTempBaseDirKey();
105static already_AddRefed<nsIFile> CreateProcessSandboxTempDir(
106 GeckoProcessType procType);
107#endif
108
109nsXREDirProvider* gDirServiceProvider = nullptr;
110nsIFile* gDataDirHomeLocal = nullptr;
111nsIFile* gDataDirHome = nullptr;
112nsCOMPtr<nsIFile> gDataDirProfileLocal = nullptr;
113nsCOMPtr<nsIFile> gDataDirProfile = nullptr;
114
115// These are required to allow nsXREDirProvider to be usable in xpcshell tests.
116// where gAppData is null.
117#if defined(XP_MACOSX) || defined(XP_UNIX1)
118static const char* GetAppName() {
119 if (gAppData) {
120 return gAppData->name;
121 }
122 return nullptr;
123}
124#endif
125
126#ifdef XP_MACOSX
127static const char* GetAppVendor() {
128 if (gAppData) {
129 return gAppData->vendor;
130 }
131 return nullptr;
132}
133#endif
134
135nsXREDirProvider::nsXREDirProvider() { gDirServiceProvider = this; }
136
137nsXREDirProvider::~nsXREDirProvider() {
138 gDirServiceProvider = nullptr;
139 gDataDirHomeLocal = nullptr;
140 gDataDirHome = nullptr;
141}
142
143already_AddRefed<nsXREDirProvider> nsXREDirProvider::GetSingleton() {
144 if (!gDirServiceProvider) {
145 new nsXREDirProvider(); // This sets gDirServiceProvider
146 }
147 return do_AddRef(gDirServiceProvider);
148}
149
150nsresult nsXREDirProvider::Initialize(nsIFile* aXULAppDir, nsIFile* aGREDir) {
151 NS_ENSURE_ARG(aXULAppDir)do { if ((__builtin_expect(!!(!(aXULAppDir)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aXULAppDir" ") failed",
nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 151); return NS_ERROR_INVALID_ARG; } } while (false)
;
152 NS_ENSURE_ARG(aGREDir)do { if ((__builtin_expect(!!(!(aGREDir)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "aGREDir" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 152); return NS_ERROR_INVALID_ARG; } } while (false)
;
153
154 mXULAppDir = aXULAppDir;
155 mGREDir = aGREDir;
156 nsCOMPtr<nsIFile> binaryPath;
157 nsresult rv = XRE_GetBinaryPath(getter_AddRefs(binaryPath));
158 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/xre/nsXREDirProvider.cpp"
, 158); return rv; } } while (false)
;
159 return binaryPath->GetParent(getter_AddRefs(mGREBinDir));
160}
161
162nsresult nsXREDirProvider::SetProfile(nsIFile* aDir, nsIFile* aLocalDir) {
163 MOZ_ASSERT(aDir && aLocalDir, "We don't support no-profile apps!")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aDir && aLocalDir)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(aDir && aLocalDir)))
, 0))) { do { } while (false); MOZ_ReportAssertionFailure("aDir && aLocalDir"
" (" "We don't support no-profile apps!" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 163); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aDir && aLocalDir"
") (" "We don't support no-profile apps!" ")"); do { *((volatile
int*)__null) = 163; __attribute__((nomerge)) ::abort(); } while
(false); } } while (false)
;
164 MOZ_ASSERT(!mProfileDir && !mProfileLocalDir,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mProfileDir && !mProfileLocalDir)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!mProfileDir && !mProfileLocalDir))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!mProfileDir && !mProfileLocalDir"
" (" "You may only set the profile directories once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 165); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mProfileDir && !mProfileLocalDir"
") (" "You may only set the profile directories once" ")"); do
{ *((volatile int*)__null) = 165; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
165 "You may only set the profile directories once")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mProfileDir && !mProfileLocalDir)>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(!mProfileDir && !mProfileLocalDir))), 0))) { do { }
while (false); MOZ_ReportAssertionFailure("!mProfileDir && !mProfileLocalDir"
" (" "You may only set the profile directories once" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 165); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mProfileDir && !mProfileLocalDir"
") (" "You may only set the profile directories once" ")"); do
{ *((volatile int*)__null) = 165; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
166
167 nsresult rv = EnsureDirectoryExists(aDir);
168 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/xre/nsXREDirProvider.cpp"
, 168); return rv; } } while (false)
;
169
170 rv = EnsureDirectoryExists(aLocalDir);
171 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/xre/nsXREDirProvider.cpp"
, 171); return rv; } } while (false)
;
172
173#ifndef XP_WIN
174 nsAutoCString profilePath;
175 rv = aDir->GetNativePath(profilePath);
176 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/xre/nsXREDirProvider.cpp"
, 176); return rv; } } while (false)
;
177
178 nsAutoCString localProfilePath;
179 rv = aLocalDir->GetNativePath(localProfilePath);
180 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/xre/nsXREDirProvider.cpp"
, 180); return rv; } } while (false)
;
181
182 if (!mozilla::IsUtf8(profilePath) || !mozilla::IsUtf8(localProfilePath)) {
183 PR_fprintf(
184 PR_STDERRPR_GetSpecialFD(PR_StandardError),
185 "Error: The profile path is not valid UTF-8. Unable to continue.\n");
186 return NS_ERROR_FAILURE;
187 }
188#endif
189
190#ifdef XP_MACOSX
191 bool same;
192 if (NS_SUCCEEDED(aDir->Equals(aLocalDir, &same))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aDir->Equals(aLocalDir
, &same))), 1)))
&& !same) {
193 // Ensure that the cache directory is not indexed by Spotlight
194 // (bug 718910). At least on OS X, the cache directory (under
195 // ~/Library/Caches/) is always the "local" user profile
196 // directory. This is confusing, since *both* user profile
197 // directories are "local" (they both exist under the user's
198 // home directory). But this usage dates back at least as far
199 // as the patch for bug 291033, where "local" seems to mean
200 // "suitable for temporary storage". Don't hide the cache
201 // directory if by some chance it and the "non-local" profile
202 // directory are the same -- there are bad side effects from
203 // hiding a profile directory under /Library/Application Support/
204 // (see bug 801883).
205 nsAutoCString cacheDir;
206 if (NS_SUCCEEDED(aLocalDir->GetNativePath(cacheDir))((bool)(__builtin_expect(!!(!NS_FAILED_impl(aLocalDir->GetNativePath
(cacheDir))), 1)))
) {
207 if (chflags(cacheDir.get(), UF_HIDDEN)) {
208 NS_WARNING("Failed to set Cache directory to HIDDEN.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to set Cache directory to HIDDEN."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 208)
;
209 }
210 }
211 }
212#endif
213
214 mProfileDir = aDir;
215 mProfileLocalDir = aLocalDir;
216 return NS_OK;
217}
218
219NS_IMPL_QUERY_INTERFACE(nsXREDirProvider, nsIDirectoryServiceProvider,nsresult nsXREDirProvider::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/xre/nsXREDirProvider.cpp"
, 221); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<nsXREDirProvider, nsIDirectoryServiceProvider
>, int32_t( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider
*>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char*
>((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID
<nsXREDirProvider, nsIDirectoryServiceProvider2>, int32_t
( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider2
*>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char*
>((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID
<nsXREDirProvider, nsIXREDirProvider>, int32_t( reinterpret_cast
<char*>(static_cast<nsIXREDirProvider*>((nsXREDirProvider
*)0x1000)) - reinterpret_cast<char*>((nsXREDirProvider*
)0x1000))}, {&mozilla::detail::kImplementedIID<nsXREDirProvider
, nsIProfileStartup>, int32_t( reinterpret_cast<char*>
(static_cast<nsIProfileStartup*>((nsXREDirProvider*)0x1000
)) - reinterpret_cast<char*>((nsXREDirProvider*)0x1000)
)}, {&mozilla::detail::kImplementedIID<nsXREDirProvider
, nsISupports>, int32_t(reinterpret_cast<char*>(static_cast
<nsISupports*>( static_cast<nsIDirectoryServiceProvider
*>((nsXREDirProvider*)0x1000))) - reinterpret_cast<char
*>((nsXREDirProvider*)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; }
220 nsIDirectoryServiceProvider2, nsIXREDirProvider,nsresult nsXREDirProvider::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/xre/nsXREDirProvider.cpp"
, 221); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<nsXREDirProvider, nsIDirectoryServiceProvider
>, int32_t( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider
*>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char*
>((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID
<nsXREDirProvider, nsIDirectoryServiceProvider2>, int32_t
( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider2
*>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char*
>((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID
<nsXREDirProvider, nsIXREDirProvider>, int32_t( reinterpret_cast
<char*>(static_cast<nsIXREDirProvider*>((nsXREDirProvider
*)0x1000)) - reinterpret_cast<char*>((nsXREDirProvider*
)0x1000))}, {&mozilla::detail::kImplementedIID<nsXREDirProvider
, nsIProfileStartup>, int32_t( reinterpret_cast<char*>
(static_cast<nsIProfileStartup*>((nsXREDirProvider*)0x1000
)) - reinterpret_cast<char*>((nsXREDirProvider*)0x1000)
)}, {&mozilla::detail::kImplementedIID<nsXREDirProvider
, nsISupports>, int32_t(reinterpret_cast<char*>(static_cast
<nsISupports*>( static_cast<nsIDirectoryServiceProvider
*>((nsXREDirProvider*)0x1000))) - reinterpret_cast<char
*>((nsXREDirProvider*)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; }
221 nsIProfileStartup)nsresult nsXREDirProvider::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/xre/nsXREDirProvider.cpp"
, 221); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(4 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&mozilla::detail
::kImplementedIID<nsXREDirProvider, nsIDirectoryServiceProvider
>, int32_t( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider
*>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char*
>((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID
<nsXREDirProvider, nsIDirectoryServiceProvider2>, int32_t
( reinterpret_cast<char*>(static_cast<nsIDirectoryServiceProvider2
*>((nsXREDirProvider*)0x1000)) - reinterpret_cast<char*
>((nsXREDirProvider*)0x1000))}, {&mozilla::detail::kImplementedIID
<nsXREDirProvider, nsIXREDirProvider>, int32_t( reinterpret_cast
<char*>(static_cast<nsIXREDirProvider*>((nsXREDirProvider
*)0x1000)) - reinterpret_cast<char*>((nsXREDirProvider*
)0x1000))}, {&mozilla::detail::kImplementedIID<nsXREDirProvider
, nsIProfileStartup>, int32_t( reinterpret_cast<char*>
(static_cast<nsIProfileStartup*>((nsXREDirProvider*)0x1000
)) - reinterpret_cast<char*>((nsXREDirProvider*)0x1000)
)}, {&mozilla::detail::kImplementedIID<nsXREDirProvider
, nsISupports>, int32_t(reinterpret_cast<char*>(static_cast
<nsISupports*>( static_cast<nsIDirectoryServiceProvider
*>((nsXREDirProvider*)0x1000))) - reinterpret_cast<char
*>((nsXREDirProvider*)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; }
222
223NS_IMETHODIMP_(MozExternalRefCountType)MozExternalRefCountType
224nsXREDirProvider::AddRef() { return 1; }
225
226NS_IMETHODIMP_(MozExternalRefCountType)MozExternalRefCountType
227nsXREDirProvider::Release() { return 0; }
228
229nsresult nsXREDirProvider::GetUserProfilesRootDir(nsIFile** aResult) {
230 nsCOMPtr<nsIFile> file;
231 nsresult rv = GetUserDataDirectory(getter_AddRefs(file), false);
232
233 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
234#if !defined(XP_UNIX1) || defined(XP_MACOSX)
235 rv = file->AppendNative("Profiles"_ns);
236#endif
237 // We must create the profile directory here if it does not exist.
238 nsresult tmp = EnsureDirectoryExists(file);
239 if (NS_FAILED(tmp)((bool)(__builtin_expect(!!(NS_FAILED_impl(tmp)), 0)))) {
240 rv = tmp;
241 }
242 }
243 file.swap(*aResult);
244 return rv;
245}
246
247nsresult nsXREDirProvider::GetUserProfilesLocalDir(nsIFile** aResult) {
248 nsCOMPtr<nsIFile> file;
249 nsresult rv = GetUserDataDirectory(getter_AddRefs(file), true);
250
251 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
252#if !defined(XP_UNIX1) || defined(XP_MACOSX)
253 rv = file->AppendNative("Profiles"_ns);
254#endif
255 // We must create the profile directory here if it does not exist.
256 nsresult tmp = EnsureDirectoryExists(file);
257 if (NS_FAILED(tmp)((bool)(__builtin_expect(!!(NS_FAILED_impl(tmp)), 0)))) {
258 rv = tmp;
Value stored to 'rv' is never read
259 }
260 }
261 file.swap(*aResult);
262 return NS_OK;
263}
264
265#ifdef MOZ_BACKGROUNDTASKS1
266nsresult nsXREDirProvider::GetBackgroundTasksProfilesRootDir(
267 nsIFile** aResult) {
268 nsCOMPtr<nsIFile> file;
269 nsresult rv = GetUserDataDirectory(getter_AddRefs(file), false);
270
271 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
272# if !defined(XP_UNIX1) || defined(XP_MACOSX)
273 // Sibling to regular user "Profiles" directory.
274 rv = file->AppendNative("Background Tasks Profiles"_ns);
275# endif
276 // We must create the directory here if it does not exist.
277 nsresult tmp = EnsureDirectoryExists(file);
278 if (NS_FAILED(tmp)((bool)(__builtin_expect(!!(NS_FAILED_impl(tmp)), 0)))) {
279 rv = tmp;
280 }
281 }
282 file.swap(*aResult);
283 return rv;
284}
285#endif
286
287#if defined(XP_UNIX1) || defined(XP_MACOSX)
288/**
289 * Get the directory that is the parent of the system-wide directories
290 * for extensions and native manifests.
291 *
292 * On OSX this is /Library/Application Support/Mozilla
293 * On Linux this is /usr/{lib,lib64}/mozilla
294 * (for 32- and 64-bit systems respsectively)
295 */
296static nsresult GetSystemParentDirectory(nsIFile** aFile) {
297 nsresult rv;
298 nsCOMPtr<nsIFile> localDir;
299# if defined(XP_MACOSX)
300 rv = GetOSXFolderType(kOnSystemDisk, kApplicationSupportFolderType,
301 getter_AddRefs(localDir));
302 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
303 rv = localDir->AppendNative("Mozilla"_ns);
304 }
305# else
306 constexpr auto dirname =
307# ifdef HAVE_USR_LIB64_DIR
308 "/usr/lib64/mozilla"_ns
309# elif defined(__OpenBSD__) || defined(__FreeBSD__)
310 "/usr/local/lib/mozilla"_ns
311# else
312 "/usr/lib/mozilla"_ns
313# endif
314 ;
315 rv = NS_NewNativeLocalFile(dirname, false, getter_AddRefs(localDir));
316# endif
317
318 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
319 localDir.forget(aFile);
320 }
321 return rv;
322}
323#endif
324
325NS_IMETHODIMPnsresult
326nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
327 nsIFile** aFile) {
328 *aPersistent = true;
329 nsresult rv = NS_ERROR_FAILURE;
330
331 nsCOMPtr<nsIFile> file;
332
333 if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR"ProfLD") ||
334 !strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP"ProfLDS")) {
335 if (mProfileLocalDir) {
336 rv = mProfileLocalDir->Clone(getter_AddRefs(file));
337 } else {
338 // Profile directories are only set up in the parent process.
339 // We don't expect every caller to check if they are in the right process,
340 // so fail immediately to avoid warning spam.
341 NS_WARNING_ASSERTION(!XRE_IsParentProcess(),do { if (!(!XRE_IsParentProcess())) { NS_DebugBreak(NS_DEBUG_WARNING
, "tried to get profile in parent too early", "!XRE_IsParentProcess()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 342); } } while (false)
342 "tried to get profile in parent too early")do { if (!(!XRE_IsParentProcess())) { NS_DebugBreak(NS_DEBUG_WARNING
, "tried to get profile in parent too early", "!XRE_IsParentProcess()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 342); } } while (false)
;
343 return NS_ERROR_FAILURE;
344 }
345 } else if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR"ProfD") ||
346 !strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP"ProfDS")) {
347 rv = GetProfileStartupDir(getter_AddRefs(file));
348 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
349 return rv;
350 }
351 } else if (!strcmp(aProperty, NS_GRE_DIR"GreD")) {
352 // On Android, internal files are inside the APK, a zip file, so this
353 // folder doesn't really make sense.
354#if !defined(MOZ_WIDGET_ANDROID)
355 rv = mGREDir->Clone(getter_AddRefs(file));
356#endif // !defined(MOZ_WIDGET_ANDROID)
357 } else if (!strcmp(aProperty, NS_GRE_BIN_DIR"GreBinD")) {
358 rv = mGREBinDir->Clone(getter_AddRefs(file));
359 } else if (!strcmp(aProperty, NS_OS_CURRENT_PROCESS_DIR"CurProcD") ||
360 !strcmp(aProperty, NS_APP_INSTALL_CLEANUP_DIR"XPIClnupD")) {
361 rv = GetAppDir()->Clone(getter_AddRefs(file));
362 } else if (!strcmp(aProperty, NS_APP_PREF_DEFAULTS_50_DIR"PrfDef")) {
363 // Same as NS_GRE_DIR
364#if !defined(MOZ_WIDGET_ANDROID)
365 // return the GRE default prefs directory here, and the app default prefs
366 // directory (if applicable) in NS_APP_PREFS_DEFAULTS_DIR_LIST.
367 rv = mGREDir->Clone(getter_AddRefs(file));
368 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/xre/nsXREDirProvider.cpp"
, 368); return rv; } } while (false)
;
369 rv = file->AppendNative("defaults"_ns);
370 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/xre/nsXREDirProvider.cpp"
, 370); return rv; } } while (false)
;
371 rv = file->AppendNative("pref"_ns);
372#endif // !defined(MOZ_WIDGET_ANDROID)
373 } else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_DIR"AppRegD") ||
374 !strcmp(aProperty, XRE_USER_APP_DATA_DIR"UAppData")) {
375 rv = GetUserAppDataDirectory(getter_AddRefs(file));
376 }
377#if defined(XP_UNIX1) || defined(XP_MACOSX)
378 else if (!strcmp(aProperty, XRE_SYS_NATIVE_MANIFESTS"XRESysNativeManifests")) {
379 rv = ::GetSystemParentDirectory(getter_AddRefs(file));
380 } else if (!strcmp(aProperty, XRE_USER_NATIVE_MANIFESTS"XREUserNativeManifests")) {
381 rv = GetUserDataDirectoryHome(getter_AddRefs(file), false);
382 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/xre/nsXREDirProvider.cpp"
, 382); return rv; } } while (false)
;
383# if defined(XP_MACOSX)
384 rv = file->AppendNative("Mozilla"_ns);
385# else // defined(XP_MACOSX)
386 rv = file->AppendNative(".mozilla"_ns);
387# endif // defined(XP_MACOSX)
388 }
389#endif // defined(XP_UNIX) || defined(XP_MACOSX)
390 else if (!strcmp(aProperty, XRE_UPDATE_ROOT_DIR"UpdRootD")) {
391 rv = GetUpdateRootDir(getter_AddRefs(file));
392 } else if (!strcmp(aProperty, XRE_OLD_UPDATE_ROOT_DIR"OldUpdRootD")) {
393 rv = GetUpdateRootDir(getter_AddRefs(file), true);
394 } else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE"AppRegF")) {
395 rv = GetUserAppDataDirectory(getter_AddRefs(file));
396 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/xre/nsXREDirProvider.cpp"
, 396); return rv; } } while (false)
;
397 rv = file->AppendNative(nsLiteralCString(APP_REGISTRY_NAME"appreg"));
398 } else if (!strcmp(aProperty, NS_APP_USER_PROFILES_ROOT_DIR"DefProfRt")) {
399 rv = GetUserProfilesRootDir(getter_AddRefs(file));
400 } else if (!strcmp(aProperty, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR"DefProfLRt")) {
401 rv = GetUserProfilesLocalDir(getter_AddRefs(file));
402 } else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE"XREExeF")) {
403 rv = XRE_GetBinaryPath(getter_AddRefs(file));
404 }
405#if defined(XP_UNIX1) || defined(XP_MACOSX)
406 else if (!strcmp(aProperty, XRE_SYS_LOCAL_EXTENSION_PARENT_DIR"XRESysLExtPD")) {
407# ifdef ENABLE_SYSTEM_EXTENSION_DIRS1
408 rv = GetSystemExtensionsDirectory(getter_AddRefs(file));
409# endif
410 }
411#endif // defined(XP_UNIX) || defined(XP_MACOSX)
412#if defined(XP_UNIX1) && !defined(XP_MACOSX)
413 else if (!strcmp(aProperty, XRE_SYS_SHARE_EXTENSION_PARENT_DIR"XRESysSExtPD")) {
414# ifdef ENABLE_SYSTEM_EXTENSION_DIRS1
415# if defined(__OpenBSD__) || defined(__FreeBSD__)
416 static const char* const sysLExtDir = "/usr/local/share/mozilla/extensions";
417# else
418 static const char* const sysLExtDir = "/usr/share/mozilla/extensions";
419# endif
420 rv = NS_NewNativeLocalFile(nsDependentCString(sysLExtDir), false,
421 getter_AddRefs(file));
422# endif
423 }
424#endif // defined(XP_UNIX) && !defined(XP_MACOSX)
425 else if (!strcmp(aProperty, XRE_USER_SYS_EXTENSION_DIR"XREUSysExt")) {
426#ifdef ENABLE_SYSTEM_EXTENSION_DIRS1
427 rv = GetSysUserExtensionsDirectory(getter_AddRefs(file));
428#endif
429 } else if (!strcmp(aProperty, XRE_USER_RUNTIME_DIR"XREUserRunTimeDir")) {
430#if defined(XP_UNIX1)
431 nsPrintfCString path("/run/user/%d/%s/", getuid(), GetAppName());
432 ToLowerCase(path);
433 rv = NS_NewNativeLocalFile(path, false, getter_AddRefs(file));
434#endif
435 } else if (!strcmp(aProperty, XRE_APP_DISTRIBUTION_DIR"XREAppDist")) {
436 bool persistent = false;
437 rv = GetFile(NS_GRE_DIR"GreD", &persistent, getter_AddRefs(file));
438 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/xre/nsXREDirProvider.cpp"
, 438); return rv; } } while (false)
;
439 rv = file->AppendNative("distribution"_ns);
440 } else if (!strcmp(aProperty, XRE_APP_FEATURES_DIR"XREAppFeat")) {
441 rv = GetAppDir()->Clone(getter_AddRefs(file));
442 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/xre/nsXREDirProvider.cpp"
, 442); return rv; } } while (false)
;
443 rv = file->AppendNative("features"_ns);
444 } else if (!strcmp(aProperty, XRE_ADDON_APP_DIR"XREAddonAppDir")) {
445 nsCOMPtr<nsIDirectoryServiceProvider> dirsvc(
446 do_GetService("@mozilla.org/file/directory_service;1", &rv));
447 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/xre/nsXREDirProvider.cpp"
, 447); return rv; } } while (false)
;
448 bool unused;
449 rv = dirsvc->GetFile("XCurProcD", &unused, getter_AddRefs(file));
450 }
451#if defined(MOZ_CONTENT_TEMP_DIR1)
452 else if (!strcmp(aProperty, NS_APP_CONTENT_PROCESS_TEMP_DIR"ContentTmpD")) {
453 if (!mContentTempDir) {
454 rv = LoadContentProcessTempDir();
455 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/xre/nsXREDirProvider.cpp"
, 455); return rv; } } while (false)
;
456 }
457 rv = mContentTempDir->Clone(getter_AddRefs(file));
458 }
459#endif // defined(MOZ_CONTENT_TEMP_DIR)
460 else if (!strcmp(aProperty, NS_APP_USER_CHROME_DIR"UChrm")) {
461 // It isn't clear why this uses GetProfileStartupDir instead of
462 // GetProfileDir. It could theoretically matter in a non-main
463 // process where some other directory provider has defined
464 // NS_APP_USER_PROFILE_50_DIR. In that scenario, using
465 // GetProfileStartupDir means this will fail instead of succeed.
466 rv = GetProfileStartupDir(getter_AddRefs(file));
467 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
468 return rv;
469 }
470 rv = file->AppendNative("chrome"_ns);
471 } else if (!strcmp(aProperty, NS_APP_PREFS_50_DIR"PrefD")) {
472 rv = GetProfileDir(getter_AddRefs(file));
473 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
474 return rv;
475 }
476 } else if (!strcmp(aProperty, NS_APP_PREFS_50_FILE"PrefF")) {
477 rv = GetProfileDir(getter_AddRefs(file));
478 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
479 return rv;
480 }
481 rv = file->AppendNative("prefs.js"_ns);
482 } else if (!strcmp(aProperty, NS_APP_PREFS_OVERRIDE_DIR"PrefDOverride")) {
483 rv = GetProfileDir(getter_AddRefs(file));
484 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
485 return rv;
486 }
487 rv = file->AppendNative(nsLiteralCString(PREF_OVERRIDE_DIRNAME"preferences"));
488 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/xre/nsXREDirProvider.cpp"
, 488); return rv; } } while (false)
;
489 rv = EnsureDirectoryExists(file);
490 } else {
491 // We don't know anything about this property. Fail without warning, because
492 // otherwise we'll get too much warning spam due to
493 // nsDirectoryService::Get() trying everything it gets with every provider.
494 return NS_ERROR_FAILURE;
495 }
496
497 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/xre/nsXREDirProvider.cpp"
, 497); return rv; } } while (false)
;
498 NS_ENSURE_TRUE(file, NS_ERROR_FAILURE)do { if ((__builtin_expect(!!(!(file)), 0))) { NS_DebugBreak(
NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "file" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 498); return NS_ERROR_FAILURE; } } while (false)
;
499
500 file.forget(aFile);
501 return NS_OK;
502}
503
504static void LoadDirIntoArray(nsIFile* dir, const char* const* aAppendList,
505 nsCOMArray<nsIFile>& aDirectories) {
506 if (!dir) return;
507
508 nsCOMPtr<nsIFile> subdir;
509 dir->Clone(getter_AddRefs(subdir));
510 if (!subdir) return;
511
512 for (const char* const* a = aAppendList; *a; ++a) {
513 subdir->AppendNative(nsDependentCString(*a));
514 }
515
516 bool exists;
517 if (NS_SUCCEEDED(subdir->Exists(&exists))((bool)(__builtin_expect(!!(!NS_FAILED_impl(subdir->Exists
(&exists))), 1)))
&& exists) {
518 aDirectories.AppendObject(subdir);
519 }
520}
521
522#if defined(MOZ_CONTENT_TEMP_DIR1)
523
524static const char* GetProcessTempBaseDirKey() { return NS_OS_TEMP_DIR"TmpD"; }
525
526//
527// Sets mContentTempDir so that it refers to the appropriate temp dir.
528// If the sandbox is enabled, NS_APP_CONTENT_PROCESS_TEMP_DIR, otherwise
529// NS_OS_TEMP_DIR is used.
530//
531nsresult nsXREDirProvider::LoadContentProcessTempDir() {
532 // The parent is responsible for creating the sandbox temp dir.
533 if (XRE_IsParentProcess()) {
534 mContentProcessSandboxTempDir =
535 CreateProcessSandboxTempDir(GeckoProcessType_Content);
536 mContentTempDir = mContentProcessSandboxTempDir;
537 } else {
538 mContentTempDir = !IsContentSandboxDisabled()
539 ? GetProcessSandboxTempDir(GeckoProcessType_Content)
540 : nullptr;
541 }
542
543 if (!mContentTempDir) {
544 nsresult rv =
545 NS_GetSpecialDirectory(NS_OS_TEMP_DIR"TmpD", getter_AddRefs(mContentTempDir));
546 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/xre/nsXREDirProvider.cpp"
, 546)
) {
547 return rv;
548 }
549 }
550
551 return NS_OK;
552}
553
554static bool IsContentSandboxDisabled() {
555 return !mozilla::BrowserTabsRemoteAutostart() ||
556 (!mozilla::IsContentSandboxEnabled());
557}
558
559//
560// If a process sandbox temp dir is to be used, returns an nsIFile
561// for the directory. Returns null if an error occurs.
562//
563static already_AddRefed<nsIFile> GetProcessSandboxTempDir(
564 GeckoProcessType type) {
565 nsCOMPtr<nsIFile> localFile;
566
567 nsresult rv = NS_GetSpecialDirectory(GetProcessTempBaseDirKey(),
568 getter_AddRefs(localFile));
569 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/xre/nsXREDirProvider.cpp"
, 569)
) {
570 return nullptr;
571 }
572
573 MOZ_ASSERT(type == GeckoProcessType_Content)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(type == GeckoProcessType_Content)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(type == GeckoProcessType_Content
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"type == GeckoProcessType_Content", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 573); AnnotateMozCrashReason("MOZ_ASSERT" "(" "type == GeckoProcessType_Content"
")"); do { *((volatile int*)__null) = 573; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
574
575 const char* prefKey = "security.sandbox.content.tempDirSuffix";
576 nsAutoString tempDirSuffix;
577 rv = mozilla::Preferences::GetString(prefKey, tempDirSuffix);
578 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/xre/nsXREDirProvider.cpp"
, 578)
|| tempDirSuffix.IsEmpty()) {
579 return nullptr;
580 }
581
582 rv = localFile->Append(u"Temp-"_ns + tempDirSuffix);
583 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/xre/nsXREDirProvider.cpp"
, 583)
) {
584 return nullptr;
585 }
586
587 return localFile.forget();
588}
589
590//
591// Create a temporary directory for use from sandboxed processes.
592// Only called in the parent. The path is derived from a UUID stored in a
593// pref which is available to content processes. Returns null
594// if the content sandbox is disabled or if an error occurs.
595//
596static already_AddRefed<nsIFile> CreateProcessSandboxTempDir(
597 GeckoProcessType procType) {
598 if ((procType == GeckoProcessType_Content) && IsContentSandboxDisabled()) {
599 return nullptr;
600 }
601
602 MOZ_ASSERT(procType == GeckoProcessType_Content)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(procType == GeckoProcessType_Content)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(procType == GeckoProcessType_Content
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"procType == GeckoProcessType_Content", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 602); AnnotateMozCrashReason("MOZ_ASSERT" "(" "procType == GeckoProcessType_Content"
")"); do { *((volatile int*)__null) = 602; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
603
604 // Get (and create if blank) temp directory suffix pref.
605 const char* pref = "security.sandbox.content.tempDirSuffix";
606
607 nsresult rv;
608 nsAutoString tempDirSuffix;
609 mozilla::Preferences::GetString(pref, tempDirSuffix);
610
611 if (tempDirSuffix.IsEmpty()) {
612 nsID uuid;
613 rv = nsID::GenerateUUIDInPlace(uuid);
614 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/xre/nsXREDirProvider.cpp"
, 614)
) {
615 return nullptr;
616 }
617
618 char uuidChars[NSID_LENGTH39];
619 uuid.ToProvidedString(uuidChars);
620 tempDirSuffix.AssignASCII(uuidChars, NSID_LENGTH39);
621# ifdef XP_UNIX1
622 // Braces in a path are somewhat annoying to deal with
623 // and pretty alien on Unix
624 tempDirSuffix.StripChars(u"{}");
625# endif
626
627 // Save the pref
628 rv = mozilla::Preferences::SetString(pref, tempDirSuffix);
629 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/xre/nsXREDirProvider.cpp"
, 629)
) {
630 // If we fail to save the pref we don't want to create the temp dir,
631 // because we won't be able to clean it up later.
632 return nullptr;
633 }
634
635 nsCOMPtr<nsIPrefService> prefsvc = mozilla::Preferences::GetService();
636 if (!prefsvc || NS_FAILED((rv = prefsvc->SavePrefFile(nullptr)))((bool)(__builtin_expect(!!(NS_FAILED_impl((rv = prefsvc->
SavePrefFile(nullptr)))), 0)))
) {
637 // Again, if we fail to save the pref file we might not be able to clean
638 // up the temp directory, so don't create one. Note that in the case
639 // the preference values allows an off main thread save, the successful
640 // return from the call doesn't mean we actually saved the file. See
641 // bug 1364496 for details.
642 NS_WARNING("Failed to save pref file, cannot create temp dir.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to save pref file, cannot create temp dir."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 642)
;
643 return nullptr;
644 }
645 }
646
647 nsCOMPtr<nsIFile> sandboxTempDir = GetProcessSandboxTempDir(procType);
648 if (!sandboxTempDir) {
649 NS_WARNING("Failed to determine sandbox temp dir path.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to determine sandbox temp dir path."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 649)
;
650 return nullptr;
651 }
652
653 // Remove the directory. It may exist due to a previous crash.
654 if (NS_FAILED(DeleteDirIfExists(sandboxTempDir))((bool)(__builtin_expect(!!(NS_FAILED_impl(DeleteDirIfExists(
sandboxTempDir))), 0)))
) {
655 NS_WARNING("Failed to reset sandbox temp dir.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to reset sandbox temp dir."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 655)
;
656 return nullptr;
657 }
658
659 // Create the directory
660 rv = sandboxTempDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
661 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
662 NS_WARNING("Failed to create sandbox temp dir.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to create sandbox temp dir."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 662)
;
663 return nullptr;
664 }
665
666 return sandboxTempDir.forget();
667}
668
669static nsresult DeleteDirIfExists(nsIFile* dir) {
670 if (dir) {
671 // Don't return an error if the directory doesn't exist.
672 nsresult rv = dir->Remove(/* aRecursive */ true);
673 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_FILE_NOT_FOUND) {
674 return rv;
675 }
676 }
677 return NS_OK;
678}
679
680#endif // defined(MOZ_CONTENT_TEMP_DIR)
681
682static const char* const kAppendPrefDir[] = {"defaults", "preferences",
683 nullptr};
684#ifdef MOZ_BACKGROUNDTASKS1
685static const char* const kAppendBackgroundTasksPrefDir[] = {
686 "defaults", "backgroundtasks", nullptr};
687#endif
688
689NS_IMETHODIMPnsresult
690nsXREDirProvider::GetFiles(const char* aProperty,
691 nsISimpleEnumerator** aResult) {
692 nsresult rv = NS_ERROR_FAILURE;
693 *aResult = nullptr;
694
695 if (!strcmp(aProperty, NS_APP_PREFS_DEFAULTS_DIR_LIST"PrefDL")) {
696 nsCOMArray<nsIFile> directories;
697
698 LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
699#ifdef MOZ_BACKGROUNDTASKS1
700 if (mozilla::BackgroundTasks::IsBackgroundTaskMode()) {
701 LoadDirIntoArray(mGREDir, kAppendBackgroundTasksPrefDir, directories);
702 LoadDirIntoArray(mXULAppDir, kAppendBackgroundTasksPrefDir, directories);
703 }
704#endif
705
706 rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile)(nsIFile::COMTypeInfo<nsIFile, void>::kIID));
707 } else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST"AChromDL")) {
708 // NS_APP_CHROME_DIR_LIST is only used to get default (native) icons
709 // for OS window decoration.
710
711 static const char* const kAppendChromeDir[] = {"chrome", nullptr};
712 nsCOMArray<nsIFile> directories;
713 LoadDirIntoArray(mXULAppDir, kAppendChromeDir, directories);
714
715 rv = NS_NewArrayEnumerator(aResult, directories, NS_GET_IID(nsIFile)(nsIFile::COMTypeInfo<nsIFile, void>::kIID));
716 }
717 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/xre/nsXREDirProvider.cpp"
, 717); return rv; } } while (false)
;
718
719 return NS_SUCCESS_AGGREGATE_RESULT;
720}
721
722NS_IMETHODIMPnsresult
723nsXREDirProvider::GetDirectory(nsIFile** aResult) {
724 NS_ENSURE_TRUE(mProfileDir, NS_ERROR_NOT_INITIALIZED)do { if ((__builtin_expect(!!(!(mProfileDir)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "mProfileDir" ") failed"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 724); return NS_ERROR_NOT_INITIALIZED; } } while (false)
;
725 return mProfileDir->Clone(aResult);
726}
727
728void nsXREDirProvider::InitializeUserPrefs() {
729 if (!mPrefsInitialized) {
730 mozilla::Preferences::InitializeUserPrefs();
731 }
732}
733
734void nsXREDirProvider::FinishInitializingUserPrefs() {
735 if (!mPrefsInitialized) {
736 mozilla::Preferences::FinishInitializingUserPrefs();
737 mPrefsInitialized = true;
738 }
739}
740
741NS_IMETHODIMPnsresult
742nsXREDirProvider::DoStartup() {
743 nsresult rv;
744
745 if (!mAppStarted) {
746 nsCOMPtr<nsIObserverService> obsSvc =
747 mozilla::services::GetObserverService();
748 if (!obsSvc) return NS_ERROR_FAILURE;
749
750 mAppStarted = true;
751
752 /*
753 Make sure we've setup prefs before profile-do-change to be able to use
754 them to track crashes and because we want to begin crash tracking before
755 other code run from this notification since they may cause crashes.
756 */
757 MOZ_ASSERT(mPrefsInitialized)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mPrefsInitialized)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(mPrefsInitialized))), 0))) {
do { } while (false); MOZ_ReportAssertionFailure("mPrefsInitialized"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 757); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mPrefsInitialized"
")"); do { *((volatile int*)__null) = 757; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
758
759 bool safeModeNecessary = false;
760 nsCOMPtr<nsIAppStartup> appStartup(
761 mozilla::components::AppStartup::Service());
762 if (appStartup) {
763 rv = appStartup->TrackStartupCrashBegin(&safeModeNecessary);
764 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0))) && rv != NS_ERROR_NOT_AVAILABLE)
765 NS_WARNING("Error while beginning startup crash tracking")NS_DebugBreak(NS_DEBUG_WARNING, "Error while beginning startup crash tracking"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 765)
;
766
767 if (!gSafeMode && safeModeNecessary) {
768 appStartup->RestartInSafeMode(nsIAppStartup::eForceQuit);
769 return NS_OK;
770 }
771 }
772
773 static const char16_t kStartup[] = {'s', 't', 'a', 'r',
774 't', 'u', 'p', '\0'};
775 obsSvc->NotifyObservers(nullptr, "profile-do-change", kStartup);
776
777 // Initialize the Enterprise Policies service in the parent process
778 // In the content process it's loaded on demand when needed
779 if (XRE_IsParentProcess()) {
780 nsCOMPtr<nsIObserver> policies(
781 do_GetService("@mozilla.org/enterprisepolicies;1"));
782 if (policies) {
783 policies->Observe(nullptr, "policies-startup", nullptr);
784 }
785 }
786
787#ifdef MOZ_THUNDERBIRD
788 bool bgtaskMode = false;
789# ifdef MOZ_BACKGROUNDTASKS1
790 bgtaskMode = mozilla::BackgroundTasks::IsBackgroundTaskMode();
791# endif
792 if (!bgtaskMode &&
793 mozilla::Preferences::GetBool(
794 "security.prompt_for_master_password_on_startup", false)) {
795# ifdef XP_MACOSX
796 // Ensure the application is initialized before the prompt is triggered.
797 // Note: calling InitializeMacApp more than once does nothing.
798 InitializeMacApp();
799# endif
800 // Prompt for the master password prior to opening application windows,
801 // to avoid the race that triggers multiple prompts (see bug 177175).
802 // We use this code until we have a better solution, possibly as
803 // described in bug 177175 comment 384.
804 nsCOMPtr<nsIPK11TokenDB> db =
805 do_GetService("@mozilla.org/security/pk11tokendb;1");
806 if (db) {
807 nsCOMPtr<nsIPK11Token> token;
808 if (NS_SUCCEEDED(db->GetInternalKeyToken(getter_AddRefs(token)))((bool)(__builtin_expect(!!(!NS_FAILED_impl(db->GetInternalKeyToken
(getter_AddRefs(token)))), 1)))
) {
809 mozilla::Unused << token->Login(false);
810 }
811 } else {
812 NS_WARNING("Failed to get nsIPK11TokenDB service.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to get nsIPK11TokenDB service."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 812)
;
813 }
814 }
815#endif
816
817 bool initExtensionManager =
818#ifdef MOZ_BACKGROUNDTASKS1
819 !mozilla::BackgroundTasks::IsBackgroundTaskMode();
820#else
821 true;
822#endif
823 if (initExtensionManager) {
824 // Init the Extension Manager
825 nsCOMPtr<nsIObserver> em =
826 do_GetService("@mozilla.org/addons/integration;1");
827 if (em) {
828 em->Observe(nullptr, "addons-startup", nullptr);
829 } else {
830 NS_WARNING("Failed to create Addons Manager.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to create Addons Manager."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 830)
;
831 }
832 }
833
834 obsSvc->NotifyObservers(nullptr, "profile-after-change", kStartup);
835
836 // Any component that has registered for the profile-after-change category
837 // should also be created at this time.
838 (void)NS_CreateServicesFromCategory("profile-after-change", nullptr,
839 "profile-after-change");
840
841 if (gSafeMode && safeModeNecessary) {
842 static const char16_t kCrashed[] = {'c', 'r', 'a', 's',
843 'h', 'e', 'd', '\0'};
844 obsSvc->NotifyObservers(nullptr, "safemode-forced", kCrashed);
845 }
846
847 // 1 = Regular mode, 2 = Safe mode, 3 = Safe mode forced
848 int mode = 1;
849 if (gSafeMode) {
850 if (safeModeNecessary)
851 mode = 3;
852 else
853 mode = 2;
854 }
855 mozilla::Telemetry::Accumulate(mozilla::Telemetry::SAFE_MODE_USAGE, mode);
856
857 obsSvc->NotifyObservers(nullptr, "profile-initial-state", nullptr);
858
859#if defined(MOZ_CONTENT_TEMP_DIR1)
860 // Makes sure the content temp dir has been loaded if it hasn't been
861 // already. In the parent this ensures it has been created before we attempt
862 // to start any content processes.
863 if (!mContentTempDir) {
864 mozilla::Unused << NS_WARN_IF(NS_FAILED(LoadContentProcessTempDir()))NS_warn_if_impl(((bool)(__builtin_expect(!!(NS_FAILED_impl(LoadContentProcessTempDir
())), 0))), "NS_FAILED(LoadContentProcessTempDir())", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 864)
;
865 }
866#endif
867 }
868 return NS_OK;
869}
870
871void nsXREDirProvider::DoShutdown() {
872 AUTO_PROFILER_LABEL("nsXREDirProvider::DoShutdown", OTHER)mozilla::AutoProfilerLabel raiiObject872( "nsXREDirProvider::DoShutdown"
, nullptr, JS::ProfilingCategoryPair::OTHER)
;
873
874 if (mAppStarted) {
875 mozilla::AppShutdown::AdvanceShutdownPhase(
876 mozilla::ShutdownPhase::AppShutdownNetTeardown, nullptr);
877 mozilla::AppShutdown::AdvanceShutdownPhase(
878 mozilla::ShutdownPhase::AppShutdownTeardown, nullptr);
879
880#ifdef DEBUG1
881 // Not having this causes large intermittent leaks. See bug 1340425.
882 if (JSContext* cx = mozilla::dom::danger::GetJSContext()) {
883 JS_GC(cx);
884 }
885#endif
886
887 mozilla::AppShutdown::AdvanceShutdownPhase(
888 mozilla::ShutdownPhase::AppShutdown, nullptr);
889 mozilla::AppShutdown::AdvanceShutdownPhase(
890 mozilla::ShutdownPhase::AppShutdownQM, nullptr);
891 mozilla::AppShutdown::AdvanceShutdownPhase(
892 mozilla::ShutdownPhase::AppShutdownTelemetry, nullptr);
893 mAppStarted = false;
894 }
895
896 gDataDirProfileLocal = nullptr;
897 gDataDirProfile = nullptr;
898
899#if defined(MOZ_CONTENT_TEMP_DIR1)
900 if (XRE_IsParentProcess()) {
901 mozilla::Unused << DeleteDirIfExists(mContentProcessSandboxTempDir);
902 }
903#endif
904}
905
906#ifdef XP_WIN
907static nsresult GetShellFolderPath(KNOWNFOLDERID folder, nsAString& _retval) {
908 DWORD flags = KF_FLAG_SIMPLE_IDLIST | KF_FLAG_DONT_VERIFY | KF_FLAG_NO_ALIAS;
909 PWSTR path = nullptr;
910
911 if (!SUCCEEDED(SHGetKnownFolderPath(folder, flags, NULL__null, &path))) {
912 return NS_ERROR_NOT_AVAILABLE;
913 }
914
915 _retval = nsDependentString(path);
916 CoTaskMemFree(path);
917 return NS_OK;
918}
919
920/**
921 * Provides a fallback for getting the path to APPDATA or LOCALAPPDATA by
922 * querying the registry when the call to SHGetSpecialFolderLocation or
923 * SHGetPathFromIDListW is unable to provide these paths (Bug 513958).
924 */
925static nsresult GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval) {
926 HKEY key;
927 LPCWSTR keyName =
928 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
929 DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName, 0, KEY_READ, &key);
930 if (res != ERROR_SUCCESS) {
931 _retval.SetLength(0);
932 return NS_ERROR_NOT_AVAILABLE;
933 }
934
935 DWORD type, size;
936 res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"), nullptr,
937 &type, nullptr, &size);
938 // The call to RegQueryValueExW must succeed, the type must be REG_SZ, the
939 // buffer size must not equal 0, and the buffer size be a multiple of 2.
940 if (res != ERROR_SUCCESS || type != REG_SZ || size == 0 || size % 2 != 0) {
941 ::RegCloseKey(key);
942 _retval.SetLength(0);
943 return NS_ERROR_NOT_AVAILABLE;
944 }
945
946 // |size| may or may not include room for the terminating null character
947 DWORD resultLen = size / 2;
948
949 if (!_retval.SetLength(resultLen, mozilla::fallible)) {
950 ::RegCloseKey(key);
951 _retval.SetLength(0);
952 return NS_ERROR_NOT_AVAILABLE;
953 }
954
955 auto begin = _retval.BeginWriting();
956
957 res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"), nullptr,
958 nullptr, (LPBYTE)begin, &size);
959 ::RegCloseKey(key);
960 if (res != ERROR_SUCCESS) {
961 _retval.SetLength(0);
962 return NS_ERROR_NOT_AVAILABLE;
963 }
964
965 if (!_retval.CharAt(resultLen - 1)) {
966 // It was already null terminated.
967 _retval.Truncate(resultLen - 1);
968 }
969
970 return NS_OK;
971}
972#endif
973
974static nsresult HashInstallPath(nsAString& aInstallPath, nsAString& aPathHash) {
975 mozilla::UniquePtr<NS_tchar[]> hash;
976 bool success = ::GetInstallHash(PromiseFlatStringTPromiseFlatString<char16_t>(aInstallPath).get(), hash);
977 if (!success) {
978 return NS_ERROR_FAILURE;
979 }
980
981 // The hash string is a NS_tchar*, which is wchar* in Windows and char*
982 // elsewhere.
983#ifdef XP_WIN
984 aPathHash.Assign(hash.get());
985#else
986 aPathHash.AssignASCII(hash.get());
987#endif
988 return NS_OK;
989}
990
991/**
992 * Gets a hash of the installation directory.
993 */
994nsresult nsXREDirProvider::GetInstallHash(nsAString& aPathHash) {
995 nsAutoString stringToHash;
996
997#ifdef XP_WIN
998 if (mozilla::widget::WinUtils::HasPackageIdentity()) {
999 // For packages, the install path includes the version number, so it isn't
1000 // a stable or consistent identifier for the installation. The package
1001 // family name is though, so use that instead of the path.
1002 stringToHash = mozilla::widget::WinUtils::GetPackageFamilyName();
1003 } else
1004#endif
1005 {
1006 nsCOMPtr<nsIFile> installDir;
1007 nsCOMPtr<nsIFile> appFile;
1008 bool per = false;
1009 nsresult rv = GetFile(XRE_EXECUTABLE_FILE"XREExeF", &per, getter_AddRefs(appFile));
1010 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/xre/nsXREDirProvider.cpp"
, 1010); return rv; } } while (false)
;
1011 rv = appFile->GetParent(getter_AddRefs(installDir));
1012 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/xre/nsXREDirProvider.cpp"
, 1012); return rv; } } while (false)
;
1013
1014 // It is possible that the path we have is on a case insensitive
1015 // filesystem in which case the path may vary depending on how the
1016 // application is called. We want to normalize the case somehow.
1017#ifdef XP_WIN
1018 // Windows provides a way to get the correct case.
1019 if (!mozilla::widget::WinUtils::ResolveJunctionPointsAndSymLinks(
1020 installDir)) {
1021 NS_WARNING("Failed to resolve install directory.")NS_DebugBreak(NS_DEBUG_WARNING, "Failed to resolve install directory."
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1021)
;
1022 }
1023#elif defined(MOZ_WIDGET_COCOA)
1024 // On OSX roundtripping through an FSRef fixes the case.
1025 FSRef ref;
1026 nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(installDir);
1027 rv = macFile->GetFSRef(&ref);
1028 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/xre/nsXREDirProvider.cpp"
, 1028); return rv; } } while (false)
;
1029 rv = NS_NewLocalFileWithFSRef(&ref, true, getter_AddRefs(macFile));
1030 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/xre/nsXREDirProvider.cpp"
, 1030); return rv; } } while (false)
;
1031 installDir = static_cast<nsIFile*>(macFile);
1032#endif
1033 // On linux XRE_EXECUTABLE_FILE already seems to be set to the correct path.
1034
1035 rv = installDir->GetPath(stringToHash);
1036 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/xre/nsXREDirProvider.cpp"
, 1036); return rv; } } while (false)
;
1037 }
1038
1039 // If we somehow failed to get an actual value, hashing an empty string could
1040 // potentially cause some serious problems given all the things this hash is
1041 // used for. So we don't allow that.
1042 if (stringToHash.IsEmpty()) {
1043 return NS_ERROR_FAILURE;
1044 }
1045
1046 return HashInstallPath(stringToHash, aPathHash);
1047}
1048
1049/**
1050 * Before bug 1555319 the directory hashed can have had an incorrect case.
1051 * Access to that hash is still available through this function. It is needed so
1052 * we can migrate users who may have an incorrect hash in profiles.ini. This
1053 * support can probably be removed in a few releases time.
1054 */
1055nsresult nsXREDirProvider::GetLegacyInstallHash(nsAString& aPathHash) {
1056 nsCOMPtr<nsIFile> installDir;
1057 nsCOMPtr<nsIFile> appFile;
1058 bool per = false;
1059 nsresult rv = GetFile(XRE_EXECUTABLE_FILE"XREExeF", &per, getter_AddRefs(appFile));
1060 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/xre/nsXREDirProvider.cpp"
, 1060); return rv; } } while (false)
;
1061 rv = appFile->GetParent(getter_AddRefs(installDir));
1062 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/xre/nsXREDirProvider.cpp"
, 1062); return rv; } } while (false)
;
1063
1064 nsAutoString installPath;
1065 rv = installDir->GetPath(installPath);
1066 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/xre/nsXREDirProvider.cpp"
, 1066); return rv; } } while (false)
;
1067
1068#ifdef XP_WIN
1069# if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE)
1070 // Convert a 64-bit install path to what would have been the 32-bit install
1071 // path to allow users to migrate their profiles from one to the other.
1072 PWSTR pathX86 = nullptr;
1073 HRESULT hres =
1074 SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, 0, nullptr, &pathX86);
1075 if (SUCCEEDED(hres)) {
1076 nsDependentString strPathX86(pathX86);
1077 if (!StringBeginsWith(installPath, strPathX86,
1078 nsCaseInsensitiveStringComparator)) {
1079 PWSTR path = nullptr;
1080 hres = SHGetKnownFolderPath(FOLDERID_ProgramFiles, 0, nullptr, &path);
1081 if (SUCCEEDED(hres)) {
1082 if (StringBeginsWith(installPath, nsDependentString(path),
1083 nsCaseInsensitiveStringComparator)) {
1084 installPath.Replace(0, wcslen(path), strPathX86);
1085 }
1086 }
1087 CoTaskMemFree(path);
1088 }
1089 }
1090 CoTaskMemFree(pathX86);
1091# endif
1092#endif
1093 return HashInstallPath(installPath, aPathHash);
1094}
1095
1096nsresult nsXREDirProvider::GetUpdateRootDir(nsIFile** aResult,
1097 bool aGetOldLocation) {
1098#ifndef XP_WIN
1099 // There is no old update location on platforms other than Windows. Windows is
1100 // the only platform for which we migrated the update directory.
1101 if (aGetOldLocation) {
1102 return NS_ERROR_NOT_IMPLEMENTED;
1103 }
1104#endif
1105 nsCOMPtr<nsIFile> updRoot;
1106 nsCOMPtr<nsIFile> appFile;
1107 bool per = false;
1108 nsresult rv = GetFile(XRE_EXECUTABLE_FILE"XREExeF", &per, getter_AddRefs(appFile));
1109 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/xre/nsXREDirProvider.cpp"
, 1109); return rv; } } while (false)
;
1110 rv = appFile->GetParent(getter_AddRefs(updRoot));
1111 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/xre/nsXREDirProvider.cpp"
, 1111); return rv; } } while (false)
;
1112
1113#ifdef XP_MACOSX
1114 nsCOMPtr<nsIFile> appRootDirFile;
1115 nsCOMPtr<nsIFile> localDir;
1116 nsAutoString appDirPath;
1117 if (NS_FAILED(appFile->GetParent(getter_AddRefs(appRootDirFile)))((bool)(__builtin_expect(!!(NS_FAILED_impl(appFile->GetParent
(getter_AddRefs(appRootDirFile)))), 0)))
||
1118 NS_FAILED(appRootDirFile->GetPath(appDirPath))((bool)(__builtin_expect(!!(NS_FAILED_impl(appRootDirFile->
GetPath(appDirPath))), 0)))
||
1119 NS_FAILED(GetUserDataDirectoryHome(getter_AddRefs(localDir), true))((bool)(__builtin_expect(!!(NS_FAILED_impl(GetUserDataDirectoryHome
(getter_AddRefs(localDir), true))), 0)))
) {
1120 return NS_ERROR_FAILURE;
1121 }
1122
1123 int32_t dotIndex = appDirPath.RFind(u".app");
1124 if (dotIndex == kNotFound) {
1125 dotIndex = appDirPath.Length();
1126 }
1127 appDirPath = Substring(appDirPath, 1, dotIndex - 1);
1128
1129 bool hasVendor = GetAppVendor() && strlen(GetAppVendor()) != 0;
1130 if (hasVendor || GetAppName()) {
1131 if (NS_FAILED(localDir->AppendNative(((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->AppendNative
( nsDependentCString(hasVendor ? GetAppVendor() : GetAppName(
))))), 0)))
1132 nsDependentCString(hasVendor ? GetAppVendor() : GetAppName())))((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->AppendNative
( nsDependentCString(hasVendor ? GetAppVendor() : GetAppName(
))))), 0)))
) {
1133 return NS_ERROR_FAILURE;
1134 }
1135 } else if (NS_FAILED(localDir->AppendNative("Mozilla"_ns))((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->AppendNative
("Mozilla"_ns))), 0)))
) {
1136 return NS_ERROR_FAILURE;
1137 }
1138
1139 if (NS_FAILED(localDir->Append(u"updates"_ns))((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->Append
(u"updates"_ns))), 0)))
||
1140 NS_FAILED(localDir->AppendRelativePath(appDirPath))((bool)(__builtin_expect(!!(NS_FAILED_impl(localDir->AppendRelativePath
(appDirPath))), 0)))
) {
1141 return NS_ERROR_FAILURE;
1142 }
1143
1144 localDir.forget(aResult);
1145 return NS_OK;
1146
1147#elif XP_WIN
1148 nsAutoString installPath;
1149 rv = updRoot->GetPath(installPath);
1150 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/xre/nsXREDirProvider.cpp"
, 1150); return rv; } } while (false)
;
1151
1152 mozilla::UniquePtr<wchar_t[]> updatePath;
1153 HRESULT hrv;
1154 if (aGetOldLocation) {
1155 hrv =
1156 GetOldUpdateDirectory(PromiseFlatStringTPromiseFlatString<char16_t>(installPath).get(), updatePath);
1157 } else {
1158 hrv = GetCommonUpdateDirectory(PromiseFlatStringTPromiseFlatString<char16_t>(installPath).get(),
1159 updatePath);
1160 }
1161 if (FAILED(hrv)) {
1162 return NS_ERROR_FAILURE;
1163 }
1164 nsAutoString updatePathStr;
1165 updatePathStr.Assign(updatePath.get());
1166 updRoot->InitWithPath(updatePathStr);
1167 updRoot.forget(aResult);
1168 return NS_OK;
1169#else
1170 updRoot.forget(aResult);
1171 return NS_OK;
1172#endif // XP_WIN
1173}
1174
1175nsresult nsXREDirProvider::GetProfileStartupDir(nsIFile** aResult) {
1176 if (mProfileDir) {
1177 return mProfileDir->Clone(aResult);
1178 }
1179
1180 // Profile directories are only set up in the parent process.
1181 // We don't expect every caller to check if they are in the right process,
1182 // so fail immediately to avoid warning spam.
1183 NS_WARNING_ASSERTION(!XRE_IsParentProcess(),do { if (!(!XRE_IsParentProcess())) { NS_DebugBreak(NS_DEBUG_WARNING
, "tried to get profile in parent too early", "!XRE_IsParentProcess()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1184); } } while (false)
1184 "tried to get profile in parent too early")do { if (!(!XRE_IsParentProcess())) { NS_DebugBreak(NS_DEBUG_WARNING
, "tried to get profile in parent too early", "!XRE_IsParentProcess()"
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1184); } } while (false)
;
1185 return NS_ERROR_FAILURE;
1186}
1187
1188nsresult nsXREDirProvider::GetProfileDir(nsIFile** aResult) {
1189 if (!mProfileDir) {
1190 nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR"ProfD",
1191 getter_AddRefs(mProfileDir));
1192 // Guard against potential buggy directory providers that fail while also
1193 // returning something.
1194 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1195 MOZ_ASSERT(!mProfileDir,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mProfileDir)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mProfileDir))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!mProfileDir" " ("
"Directory provider failed but returned a value" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1196); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mProfileDir"
") (" "Directory provider failed but returned a value" ")");
do { *((volatile int*)__null) = 1196; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
1196 "Directory provider failed but returned a value")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!mProfileDir)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!mProfileDir))), 0))) { do {
} while (false); MOZ_ReportAssertionFailure("!mProfileDir" " ("
"Directory provider failed but returned a value" ")", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1196); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!mProfileDir"
") (" "Directory provider failed but returned a value" ")");
do { *((volatile int*)__null) = 1196; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1197 mProfileDir = nullptr;
1198 }
1199 }
1200 // If we failed to get mProfileDir, this will warn for us if appropriate.
1201 return GetProfileStartupDir(aResult);
1202}
1203
1204NS_IMETHODIMPnsresult
1205nsXREDirProvider::SetUserDataDirectory(nsIFile* aFile, bool aLocal) {
1206 if (aLocal) {
1207 NS_IF_RELEASE(gDataDirHomeLocal)do { if (gDataDirHomeLocal) { (gDataDirHomeLocal)->Release
(); (gDataDirHomeLocal) = 0; } } while (0)
;
1208 NS_IF_ADDREF(gDataDirHomeLocal = aFile)ns_if_addref(gDataDirHomeLocal = aFile);
1209 } else {
1210 NS_IF_RELEASE(gDataDirHome)do { if (gDataDirHome) { (gDataDirHome)->Release(); (gDataDirHome
) = 0; } } while (0)
;
1211 NS_IF_ADDREF(gDataDirHome = aFile)ns_if_addref(gDataDirHome = aFile);
1212 }
1213
1214 return NS_OK;
1215}
1216
1217/* static */
1218nsresult nsXREDirProvider::SetUserDataProfileDirectory(nsCOMPtr<nsIFile>& aFile,
1219 bool aLocal) {
1220 if (aLocal) {
1221 gDataDirProfileLocal = aFile;
1222 } else {
1223 gDataDirProfile = aFile;
1224 }
1225
1226 return NS_OK;
1227}
1228
1229nsresult nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile,
1230 bool aLocal) {
1231 // Copied from nsAppFileLocationProvider (more or less)
1232 nsresult rv;
1233 nsCOMPtr<nsIFile> localDir;
1234
1235 if (aLocal && gDataDirHomeLocal) {
1236 return gDataDirHomeLocal->Clone(aFile);
1237 }
1238 if (!aLocal && gDataDirHome) {
1239 return gDataDirHome->Clone(aFile);
1240 }
1241
1242#if defined(XP_MACOSX)
1243 FSRef fsRef;
1244 OSType folderType;
1245 if (aLocal) {
1246 folderType = kCachedDataFolderType;
1247 } else {
1248# ifdef MOZ_THUNDERBIRD
1249 folderType = kDomainLibraryFolderType;
1250# else
1251 folderType = kApplicationSupportFolderType;
1252# endif
1253 }
1254 OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
1255 NS_ENSURE_FALSE(err, NS_ERROR_FAILURE)do { if ((__builtin_expect(!!(!(!(err))), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "!(err)" ") failed", nullptr
, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1255); return NS_ERROR_FAILURE; } } while (false)
;
1256
1257 rv = NS_NewNativeLocalFile(""_ns, true, getter_AddRefs(localDir));
1258 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/xre/nsXREDirProvider.cpp"
, 1258); return rv; } } while (false)
;
1259
1260 nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
1261 NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED)do { if ((__builtin_expect(!!(!(dirFileMac)), 0))) { NS_DebugBreak
(NS_DEBUG_WARNING, "NS_ENSURE_TRUE(" "dirFileMac" ") failed",
nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1261); return NS_ERROR_UNEXPECTED; } } while (false)
;
1262
1263 rv = dirFileMac->InitWithFSRef(&fsRef);
1264 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/xre/nsXREDirProvider.cpp"
, 1264); return rv; } } while (false)
;
1265
1266 localDir = dirFileMac;
1267#elif defined(XP_IOS)
1268 nsAutoCString userDir;
1269 if (GetUIKitDirectory(aLocal, userDir)) {
1270 rv = NS_NewNativeLocalFile(userDir, true, getter_AddRefs(localDir));
1271 } else {
1272 rv = NS_ERROR_FAILURE;
1273 }
1274 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/xre/nsXREDirProvider.cpp"
, 1274); return rv; } } while (false)
;
1275#elif defined(XP_WIN)
1276 nsString path;
1277 if (aLocal) {
1278 rv = GetShellFolderPath(FOLDERID_LocalAppData, path);
1279 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) rv = GetRegWindowsAppDataFolder(aLocal, path);
1280 }
1281 if (!aLocal || NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1282 rv = GetShellFolderPath(FOLDERID_RoamingAppData, path);
1283 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1284 if (!aLocal) rv = GetRegWindowsAppDataFolder(aLocal, path);
1285 }
1286 }
1287 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/xre/nsXREDirProvider.cpp"
, 1287); return rv; } } while (false)
;
1288
1289 rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir));
1290#elif defined(XP_UNIX1)
1291 const char* homeDir = getenv("HOME");
1292 if (!homeDir || !*homeDir) return NS_ERROR_FAILURE;
1293
1294# ifdef ANDROID /* We want (ProfD == ProfLD) on Android. */
1295 aLocal = false;
1296# endif
1297
1298 if (aLocal) {
1299 // If $XDG_CACHE_HOME is defined use it, otherwise use $HOME/.cache.
1300 const char* cacheHome = getenv("XDG_CACHE_HOME");
1301 if (cacheHome && *cacheHome) {
1302 rv = NS_NewNativeLocalFile(nsDependentCString(cacheHome), true,
1303 getter_AddRefs(localDir));
1304 } else {
1305 rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
1306 getter_AddRefs(localDir));
1307 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) rv = localDir->AppendNative(".cache"_ns);
1308 }
1309 } else {
1310 rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
1311 getter_AddRefs(localDir));
1312 }
1313#else
1314# error "Don't know how to get product dir on your platform"
1315#endif
1316
1317 NS_IF_ADDREF(*aFile = localDir)ns_if_addref(*aFile = localDir);
1318 return rv;
1319}
1320
1321nsresult nsXREDirProvider::GetSysUserExtensionsDirectory(nsIFile** aFile) {
1322 nsCOMPtr<nsIFile> localDir;
1323 nsresult rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), false);
1324 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/xre/nsXREDirProvider.cpp"
, 1324); return rv; } } while (false)
;
1325
1326 rv = AppendSysUserExtensionPath(localDir);
1327 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/xre/nsXREDirProvider.cpp"
, 1327); return rv; } } while (false)
;
1328
1329 rv = EnsureDirectoryExists(localDir);
1330 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/xre/nsXREDirProvider.cpp"
, 1330); return rv; } } while (false)
;
1331
1332 localDir.forget(aFile);
1333 return NS_OK;
1334}
1335
1336#if defined(XP_UNIX1) || defined(XP_MACOSX)
1337nsresult nsXREDirProvider::GetSystemExtensionsDirectory(nsIFile** aFile) {
1338 nsresult rv;
1339 nsCOMPtr<nsIFile> localDir;
1340
1341 rv = GetSystemParentDirectory(getter_AddRefs(localDir));
1342 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1343 constexpr auto sExtensions =
1344# if defined(XP_MACOSX)
1345 "Extensions"_ns
1346# else
1347 "extensions"_ns
1348# endif
1349 ;
1350
1351 rv = localDir->AppendNative(sExtensions);
1352 if (NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
1353 localDir.forget(aFile);
1354 }
1355 }
1356 return rv;
1357}
1358#endif
1359
1360nsresult nsXREDirProvider::GetUserDataDirectory(nsIFile** aFile, bool aLocal) {
1361 nsCOMPtr<nsIFile> localDir;
1362
1363 if (aLocal && gDataDirProfileLocal) {
1364 return gDataDirProfileLocal->Clone(aFile);
1365 }
1366 if (!aLocal && gDataDirProfile) {
1367 return gDataDirProfile->Clone(aFile);
1368 }
1369
1370 nsresult rv = GetUserDataDirectoryHome(getter_AddRefs(localDir), aLocal);
1371 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/xre/nsXREDirProvider.cpp"
, 1371); return rv; } } while (false)
;
1372
1373 rv = AppendProfilePath(localDir, aLocal);
1374 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/xre/nsXREDirProvider.cpp"
, 1374); return rv; } } while (false)
;
1375
1376 rv = EnsureDirectoryExists(localDir);
1377 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/xre/nsXREDirProvider.cpp"
, 1377); return rv; } } while (false)
;
1378
1379 nsXREDirProvider::SetUserDataProfileDirectory(localDir, aLocal);
1380
1381 localDir.forget(aFile);
1382 return NS_OK;
1383}
1384
1385nsresult nsXREDirProvider::EnsureDirectoryExists(nsIFile* aDirectory) {
1386 nsresult rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700);
1387
1388 if (rv == NS_ERROR_FILE_ALREADY_EXISTS) {
1389 rv = NS_OK;
1390 }
1391 return rv;
1392}
1393
1394nsresult nsXREDirProvider::AppendSysUserExtensionPath(nsIFile* aFile) {
1395 NS_ASSERTION(aFile, "Null pointer!")do { if (!(aFile)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Null pointer!"
, "aFile", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1395); MOZ_PretendNoReturn(); } } while (0)
;
1396
1397 nsresult rv;
1398
1399#if defined(XP_MACOSX) || defined(XP_WIN)
1400
1401 static const char* const sXR = "Mozilla";
1402 rv = aFile->AppendNative(nsDependentCString(sXR));
1403 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/xre/nsXREDirProvider.cpp"
, 1403); return rv; } } while (false)
;
1404
1405 static const char* const sExtensions = "Extensions";
1406 rv = aFile->AppendNative(nsDependentCString(sExtensions));
1407 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/xre/nsXREDirProvider.cpp"
, 1407); return rv; } } while (false)
;
1408
1409#elif defined(XP_UNIX1)
1410
1411 static const char* const sXR = ".mozilla";
1412 rv = aFile->AppendNative(nsDependentCString(sXR));
1413 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/xre/nsXREDirProvider.cpp"
, 1413); return rv; } } while (false)
;
1414
1415 static const char* const sExtensions = "extensions";
1416 rv = aFile->AppendNative(nsDependentCString(sExtensions));
1417 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/xre/nsXREDirProvider.cpp"
, 1417); return rv; } } while (false)
;
1418
1419#else
1420# error "Don't know how to get XRE user extension path on your platform"
1421#endif
1422 return NS_OK;
1423}
1424
1425nsresult nsXREDirProvider::AppendProfilePath(nsIFile* aFile, bool aLocal) {
1426 NS_ASSERTION(aFile, "Null pointer!")do { if (!(aFile)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Null pointer!"
, "aFile", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1426); MOZ_PretendNoReturn(); } } while (0)
;
1427
1428 // If there is no XREAppData then there is no information to use to build
1429 // the profile path so just do nothing. This should only happen in xpcshell
1430 // tests.
1431 if (!gAppData) {
1432 return NS_OK;
1433 }
1434
1435 nsAutoCString profile;
1436 nsAutoCString appName;
1437 nsAutoCString vendor;
1438 if (gAppData->profile) {
1439 profile = gAppData->profile;
1440 } else {
1441 appName = gAppData->name;
1442 vendor = gAppData->vendor;
1443 }
1444
1445 nsresult rv = NS_OK;
1446
1447#if defined(XP_MACOSX)
1448 if (!profile.IsEmpty()) {
1449 rv = AppendProfileString(aFile, profile.get());
1450 } else {
1451 // Note that MacOS ignores the vendor when creating the profile hierarchy -
1452 // all application preferences directories live alongside one another in
1453 // ~/Library/Application Support/
1454 rv = aFile->AppendNative(appName);
1455 }
1456 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/xre/nsXREDirProvider.cpp"
, 1456); return rv; } } while (false)
;
1457
1458#elif defined(XP_WIN)
1459 if (!profile.IsEmpty()) {
1460 rv = AppendProfileString(aFile, profile.get());
1461 } else {
1462 if (!vendor.IsEmpty()) {
1463 rv = aFile->AppendNative(vendor);
1464 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/xre/nsXREDirProvider.cpp"
, 1464); return rv; } } while (false)
;
1465 }
1466 rv = aFile->AppendNative(appName);
1467 }
1468 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/xre/nsXREDirProvider.cpp"
, 1468); return rv; } } while (false)
;
1469
1470#elif defined(ANDROID)
1471 // The directory used for storing profiles
1472 // The parent of this directory is set in GetUserDataDirectoryHome
1473 // XXX: handle gAppData->profile properly
1474 // XXXsmaug ...and the rest of the profile creation!
1475 rv = aFile->AppendNative(nsDependentCString("mozilla"));
1476 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/xre/nsXREDirProvider.cpp"
, 1476); return rv; } } while (false)
;
1477#elif defined(XP_UNIX1)
1478 nsAutoCString folder;
1479 // Make it hidden (by starting with "."), except when local (the
1480 // profile is already under ~/.cache or XDG_CACHE_HOME).
1481 if (!aLocal) folder.Assign('.');
1482
1483 if (!profile.IsEmpty()) {
1484 // Skip any leading path characters
1485 const char* profileStart = profile.get();
1486 while (*profileStart == '/' || *profileStart == '\\') profileStart++;
1487
1488 // On the off chance that someone wanted their folder to be hidden don't
1489 // let it become ".."
1490 if (*profileStart == '.' && !aLocal) profileStart++;
1491
1492 folder.Append(profileStart);
1493 ToLowerCase(folder);
1494
1495 rv = AppendProfileString(aFile, folder.BeginReading());
1496 } else {
1497 if (!vendor.IsEmpty()) {
1498 folder.Append(vendor);
1499 ToLowerCase(folder);
1500
1501 rv = aFile->AppendNative(folder);
1502 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/xre/nsXREDirProvider.cpp"
, 1502); return rv; } } while (false)
;
1503
1504 folder.Truncate();
1505 }
1506
1507 // This can be the case in tests.
1508 if (!appName.IsEmpty()) {
1509 folder.Append(appName);
1510 ToLowerCase(folder);
1511
1512 rv = aFile->AppendNative(folder);
1513 }
1514 }
1515 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/xre/nsXREDirProvider.cpp"
, 1515); return rv; } } while (false)
;
1516
1517#else
1518# error "Don't know how to get profile path on your platform"
1519#endif
1520 return NS_OK;
1521}
1522
1523nsresult nsXREDirProvider::AppendProfileString(nsIFile* aFile,
1524 const char* aPath) {
1525 NS_ASSERTION(aFile, "Null file!")do { if (!(aFile)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Null file!"
, "aFile", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1525); MOZ_PretendNoReturn(); } } while (0)
;
1526 NS_ASSERTION(aPath, "Null path!")do { if (!(aPath)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Null path!"
, "aPath", "/var/lib/jenkins/workspace/firefox-scan-build/toolkit/xre/nsXREDirProvider.cpp"
, 1526); MOZ_PretendNoReturn(); } } while (0)
;
1527
1528 nsAutoCString pathDup(aPath);
1529
1530 char* path = pathDup.BeginWriting();
1531
1532 nsresult rv;
1533 char* subdir;
1534 while ((subdir = NS_strtok("/\\", &path))) {
1535 rv = aFile->AppendNative(nsDependentCString(subdir));
1536 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/xre/nsXREDirProvider.cpp"
, 1536); return rv; } } while (false)
;
1537 }
1538
1539 return NS_OK;
1540}