Bug 1332523 - Make GetBootstrap take the path to an arbitrary file next to libxul. r=bsmedberg
The FileExists check can be removed because the code loading the library
will handle that case already.
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -236,52 +236,27 @@ static int do_main(int argc, char* argv[
#ifdef LIBFUZZER
if (getenv("LIBFUZZER"))
gBootstrap->XRE_LibFuzzerSetMain(argc, argv, libfuzzer_main);
#endif
return gBootstrap->XRE_main(argc, argv, config);
}
-static bool
-FileExists(const char *path)
-{
-#ifdef XP_WIN
- wchar_t wideDir[MAX_PATH];
- MultiByteToWideChar(CP_UTF8, 0, path, -1, wideDir, MAX_PATH);
- DWORD fileAttrs = GetFileAttributesW(wideDir);
- return fileAttrs != INVALID_FILE_ATTRIBUTES;
-#else
- return access(path, R_OK) == 0;
-#endif
-}
-
static nsresult
InitXPCOMGlue(const char *argv0)
{
char exePath[MAXPATHLEN];
nsresult rv = mozilla::BinaryPath::Get(argv0, exePath);
if (NS_FAILED(rv)) {
Output("Couldn't find the application directory.\n");
return rv;
}
- char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
- if (!lastSlash ||
- (size_t(lastSlash - exePath) > MAXPATHLEN - sizeof(XPCOM_DLL) - 1))
- return NS_ERROR_FAILURE;
-
- strcpy(lastSlash + 1, XPCOM_DLL);
-
- if (!FileExists(exePath)) {
- Output("Could not find the Mozilla runtime.\n");
- return NS_ERROR_FAILURE;
- }
-
gBootstrap = mozilla::GetBootstrap(exePath);
if (!gBootstrap) {
Output("Couldn't load XPCOM.\n");
return NS_ERROR_FAILURE;
}
// This will set this thread as the main thread.
gBootstrap->NS_LogInit();
--- a/xpcom/glue/standalone/nsXPCOMGlue.cpp
+++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp
@@ -8,16 +8,17 @@
#include "nspr.h"
#include "nsDebug.h"
#include "nsIServiceManager.h"
#include "nsXPCOMPrivate.h"
#include "nsCOMPtr.h"
#include <stdlib.h>
#include <stdio.h>
+#include <string>
#include "mozilla/FileUtils.h"
#include "mozilla/Sprintf.h"
using namespace mozilla;
#define XPCOM_DEPENDENT_LIBS_LIST "dependentlibs.list"
@@ -386,20 +387,27 @@ namespace mozilla {
Bootstrap::UniquePtr
GetBootstrap(const char* aXPCOMFile)
{
#ifdef MOZ_GSLICE_INIT
GSliceInit gSliceInit;
#endif
if (!aXPCOMFile) {
- aXPCOMFile = XPCOM_DLL;
+ return nullptr;
}
- if (NS_FAILED(XPCOMGlueLoad(aXPCOMFile))) {
+ std::string file(aXPCOMFile);
+ size_t lastSlash = file.rfind(XPCOM_FILE_PATH_SEPARATOR[0]);
+ if (lastSlash == std::string::npos) {
+ return nullptr;
+ }
+ file.replace(lastSlash + 1, std::string::npos, XPCOM_DLL);
+
+ if (NS_FAILED(XPCOMGlueLoad(file.c_str()))) {
return nullptr;
}
GetBootstrapType func = (GetBootstrapType)GetSymbol(sTop->libHandle, "XRE_GetBootstrap");
if (!func) {
return nullptr;
}