aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/syntax
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-03-07 03:02:12 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-07 03:02:12 +0100
commit84ac0732fdd228c497d6a6a4997ca492bb16d482 (patch)
treeb468b78576a8e8a185392bbae3942fd80e11be23 /ui/syntax
parentsyntax: safe dll loading (diff)
downloadwireguard-windows-84ac0732fdd228c497d6a6a4997ca492bb16d482.tar.xz
wireguard-windows-84ac0732fdd228c497d6a6a4997ca492bb16d482.zip
syntax: lazily load ui library
This way we don't have msftedit.dll loaded into the address space of the process doing real crypto. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/syntax')
-rw-r--r--ui/syntax/confview.c6
-rw-r--r--ui/syntax/confview.go5
-rw-r--r--ui/syntax/syntaxedit.c6
-rw-r--r--ui/syntax/syntaxedit.go5
4 files changed, 10 insertions, 12 deletions
diff --git a/ui/syntax/confview.c b/ui/syntax/confview.c
index 32d100e8..b7e6657b 100644
--- a/ui/syntax/confview.c
+++ b/ui/syntax/confview.c
@@ -142,14 +142,16 @@ static LRESULT CALLBACK child_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lP
return parent_proc(hWnd, Msg, wParam, lParam);
}
+static long has_loaded = 0;
+
bool register_conf_view(void)
{
WNDCLASSEXW class = { .cbSize = sizeof(WNDCLASSEXW) };
WNDPROC pp;
HANDLE lib;
- if (parent_proc)
- return true;
+ if (InterlockedCompareExchange(&has_loaded, 1, 0) != 0)
+ return !!parent_proc;
lib = LoadLibraryExW(L"msftedit.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (!lib)
diff --git a/ui/syntax/confview.go b/ui/syntax/confview.go
index b88a7702..ef1c4530 100644
--- a/ui/syntax/confview.go
+++ b/ui/syntax/confview.go
@@ -23,10 +23,6 @@ type ConfView struct {
lastRtf string
}
-func init() {
- C.register_conf_view()
-}
-
func (cv *ConfView) LayoutFlags() walk.LayoutFlags {
return walk.GrowableHorz | walk.GrowableVert | walk.GreedyHorz | walk.GreedyVert
}
@@ -138,6 +134,7 @@ func (cv *ConfView) SetConfiguration(conf *conf.Config) {
}
func NewConfView(parent walk.Container) (*ConfView, error) {
+ C.register_conf_view()
cv := &ConfView{
lastRtf: "",
}
diff --git a/ui/syntax/syntaxedit.c b/ui/syntax/syntaxedit.c
index 95356331..6c6de295 100644
--- a/ui/syntax/syntaxedit.c
+++ b/ui/syntax/syntaxedit.c
@@ -279,14 +279,16 @@ static LRESULT CALLBACK child_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lP
return parent_proc(hWnd, Msg, wParam, lParam);
}
+static long has_loaded = 0;
+
bool register_syntax_edit(void)
{
WNDCLASSEXW class = { .cbSize = sizeof(WNDCLASSEXW) };
WNDPROC pp;
HANDLE lib;
- if (parent_proc)
- return true;
+ if (InterlockedCompareExchange(&has_loaded, 1, 0) != 0)
+ return !!parent_proc;
lib = LoadLibraryExW(L"msftedit.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (!lib)
diff --git a/ui/syntax/syntaxedit.go b/ui/syntax/syntaxedit.go
index ec1e54b8..95cf576c 100644
--- a/ui/syntax/syntaxedit.go
+++ b/ui/syntax/syntaxedit.go
@@ -59,10 +59,6 @@ type SyntaxEdit struct {
privateKeyPublisher PrivateKeyPublisher
}
-func init() {
- C.register_syntax_edit()
-}
-
func (se *SyntaxEdit) LayoutFlags() walk.LayoutFlags {
return walk.GrowableHorz | walk.GrowableVert | walk.GreedyHorz | walk.GreedyVert
}
@@ -122,6 +118,7 @@ func (se *SyntaxEdit) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr)
}
func NewSyntaxEdit(parent walk.Container) (*SyntaxEdit, error) {
+ C.register_syntax_edit()
se := &SyntaxEdit{}
err := walk.InitWidget(
se,