From 80b073b649fca54f5021f6b4ae45a1e74a07faea Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Mon, 15 May 2023 22:42:32 -0400 Subject: [PATCH] Correctly handle Unicode names for exit event Currently we use the ANSI version of CreateEvent causing name of the exit event to be interpreted differently depending on the code page in effect. Internally all strings parsed from command line and config file are stored as UTF8-encoded Uniode. When passed to Windows API calls, these should be converted to UTF16 and wide character version of the API should be used. CreateEvent calls for unnamed events are left unchanged as there is no text-encoding dependence in those cases. Signed-off-by: Selva Nair Acked-by: Lev Stipakov Message-Id: <20230516024232.2680491-1-selva.nair@gmail.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26666.html Signed-off-by: Gert Doering --- src/openvpn/win32.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index 1ae3723f1..25da54ab2 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -509,19 +509,19 @@ win32_signal_open(struct win32_signal *ws, && !HANDLE_DEFINED(ws->in.read) && exit_event_name) { struct security_attributes sa; + struct gc_arena gc = gc_new(); + const wchar_t *exit_event_nameW = wide_string(exit_event_name, &gc); if (!init_security_attributes_allow_all(&sa)) { msg(M_ERR, "Error: win32_signal_open: init SA failed"); } - ws->in.read = CreateEvent(&sa.sa, - TRUE, - exit_event_initial_state ? TRUE : FALSE, - exit_event_name); + ws->in.read = CreateEventW(&sa.sa, TRUE, exit_event_initial_state ? TRUE : FALSE, + exit_event_nameW); if (ws->in.read == NULL) { - msg(M_WARN|M_ERRNO, "NOTE: CreateEvent '%s' failed", exit_event_name); + msg(M_WARN|M_ERRNO, "NOTE: CreateEventW '%s' failed", exit_event_name); } else { @@ -534,6 +534,7 @@ win32_signal_open(struct win32_signal *ws, ws->mode = WSO_MODE_SERVICE; } } + gc_free(&gc); } /* set the ctrl handler in both console and service modes */ if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) win_ctrl_handler, true)) -- 2.47.2