Skip to content

Commit f17990f

Browse files
committed
Bug 552864 part 1 - Move DLL blocklist in XRE, and inline NS_SetDllDirectory and environment sanitization, which now needs to be called manually. r=ehsan,r=bsmedberg
1 parent 228b060 commit f17990f

File tree

10 files changed

+58
-96
lines changed

10 files changed

+58
-96
lines changed

browser/app/nsBrowserApp.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
#include "nsStringGlue.h"
5555

5656
#ifdef XP_WIN
57-
// we want to use the DLL blocklist if possible
58-
#define XRE_WANT_DLL_BLOCKLIST
5957
// we want a wmain entry point
6058
#include "nsWindowsWMain.cpp"
6159
#endif
@@ -110,6 +108,10 @@ int main(int argc, char* argv[])
110108
{
111109
ScopedLogging log;
112110

111+
#ifdef XRE_HAS_DLL_BLOCKLIST
112+
XRE_SetupDllBlocklist();
113+
#endif
114+
113115
nsCOMPtr<nsILocalFile> appini;
114116
nsresult rv = XRE_GetBinaryPath(argv[0], getter_AddRefs(appini));
115117
if (NS_FAILED(rv)) {

dom/plugins/ipc/PluginProcessChild.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ PluginProcessChild::Init()
146146
protectCurrentDirectory = false;
147147
}
148148
if (protectCurrentDirectory) {
149+
SanitizeEnvironmentVariables();
149150
NS_SetDllDirectory(L"");
150151
}
151152

ipc/app/MozillaRuntimeMain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ main(int argc, char* argv[])
7373
// avoid it for unsupported plugins. See PluginProcessChild::Init for
7474
// the details.
7575
if (proctype != GeckoProcessType_Plugin) {
76+
mozilla::SanitizeEnvironmentVariables();
7677
mozilla::NS_SetDllDirectory(L"");
7778
}
7879
#endif

toolkit/xre/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ endif
9292

9393
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
9494
CPPSRCS += nsNativeAppSupportWin.cpp
95+
CPPSRCS += nsWindowsDllBlocklist.cpp
9596
DEFINES += -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE
9697
EXPORTS = nsWindowsDllInterceptor.h
9798
else

toolkit/xre/nsWindowsDllBlocklist.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040

4141
#include <stdio.h>
4242

43+
#ifdef XRE_WANT_DLL_BLOCKLIST
44+
#define XRE_SetupDllBlocklist SetupDllBlocklist
45+
#else
46+
#include "nsXULAppAPI.h"
47+
#endif
48+
4349
#include "nsAutoPtr.h"
4450

4551
#include "prlog.h"
@@ -208,7 +214,7 @@ patched_LdrLoadDll (PWCHAR filePath, PULONG flags, PUNICODE_STRING moduleFileNam
208214
WindowsDllInterceptor NtDllIntercept;
209215

210216
void
211-
SetupDllBlocklist()
217+
XRE_SetupDllBlocklist()
212218
{
213219
NtDllIntercept.Init("ntdll.dll");
214220

toolkit/xre/nsWindowsWMain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ FreeAllocStrings(int argc, char **argv)
7676
int wmain(int argc, WCHAR **argv)
7777
{
7878
#ifndef XRE_DONT_PROTECT_DLL_LOAD
79+
mozilla::SanitizeEnvironmentVariables();
7980
mozilla::NS_SetDllDirectory(L"");
8081
#endif
8182

xpcom/base/Makefile.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ EXPORTS_mozilla = \
9898
$(NULL)
9999

100100
ifeq (windows,$(MOZ_WIDGET_TOOLKIT))
101-
CPPSRCS += nsSetDllDirectory.cpp
102101
CPPSRCS += nsCrashOnException.cpp
103102
endif
104103

xpcom/base/nsSetDllDirectory.cpp

Lines changed: 0 additions & 91 deletions
This file was deleted.

xpcom/base/nsSetDllDirectory.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,48 @@
4343
#error This file only makes sense on Windows.
4444
#endif
4545

46+
#include <windows.h>
4647
#include <nscore.h>
48+
#include <stdlib.h>
4749

4850
namespace mozilla {
4951

52+
static void SanitizeEnvironmentVariables()
53+
{
54+
DWORD bufferSize = GetEnvironmentVariableW(L"PATH", NULL, 0);
55+
if (bufferSize) {
56+
wchar_t* originalPath = new wchar_t[bufferSize];
57+
if (bufferSize - 1 == GetEnvironmentVariableW(L"PATH", originalPath, bufferSize)) {
58+
bufferSize = ExpandEnvironmentStringsW(originalPath, NULL, 0);
59+
if (bufferSize) {
60+
wchar_t* newPath = new wchar_t[bufferSize];
61+
if (ExpandEnvironmentStringsW(originalPath,
62+
newPath,
63+
bufferSize)) {
64+
SetEnvironmentVariableW(L"PATH", newPath);
65+
}
66+
delete[] newPath;
67+
}
68+
}
69+
delete[] originalPath;
70+
}
71+
}
72+
5073
// Sets the directory from which DLLs can be loaded if the SetDllDirectory OS
5174
// API is available.
52-
XPCOM_API(void) NS_SetDllDirectory(const WCHAR *aDllDirectory);
75+
// You must call SanitizeEnvironmentVariables before this function when calling
76+
// it the first time.
77+
static inline void NS_SetDllDirectory(const WCHAR *aDllDirectory)
78+
{
79+
typedef BOOL
80+
(WINAPI *pfnSetDllDirectory) (LPCWSTR);
81+
pfnSetDllDirectory setDllDirectory = nsnull;
82+
setDllDirectory = reinterpret_cast<pfnSetDllDirectory>
83+
(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetDllDirectoryW"));
84+
if (setDllDirectory) {
85+
setDllDirectory(aDllDirectory);
86+
}
87+
}
5388

5489
}
5590

xpcom/build/nsXULAppAPI.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,4 +562,11 @@ XRE_API(bool,
562562

563563
XRE_API(void,
564564
XRE_InstallX11ErrorHandler, ())
565+
566+
#if defined(_MSC_VER) && defined(_M_IX86)
567+
#define XRE_HAS_DLL_BLOCKLIST
568+
XRE_API(void,
569+
XRE_SetupDllBlocklist, ())
570+
#endif
571+
565572
#endif // _nsXULAppAPI_h__

0 commit comments

Comments
 (0)