Bug Summary

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