Correctly handle Unicode names for exit event
PATCH 1/1 Correctly handle Unicode names for exit event
From: Selva Nair <[email protected]...>
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.
--- src/openvpn/win32.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
src/openvpn/win32.c +6 -5
@@ -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))
Signature · 1 line
2.34.1
Hi,
My understanding is that this is related to
https://github.com/OpenVPN/openvpn-gui/issues/626#issuecomment-1546934297
since normally we use string representation of HANDLE value as an event name.
Looks good to me. Also compiled and tested.
ti 16. toukok. 2023 klo 5.57 [email protected]... kirjoitti:
Quoted 64 lines
From: Selva Nair <[email protected]...>
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 <[email protected]...>--- src/openvpn/win32.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)src/openvpn/win32.c +6
-6@@ -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.34.1
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 1 line
-Lev
Explanation makes sense, though it's only relevant for "outside openvpn GUI" use cases. But I look forward to a submission of "openvpn windows CLI" :-)
Test compiled on MinGW. Does our GH windows test setup use the event mechanism? Or "classic signals"?
Your patch has been applied to the master and release/2.6 branch.
commit 80b073b649fca54f5021f6b4ae45a1e74a07faea (master) commit 232a0fac1ede6724688cbd4f5d5f2e619f647e16 (release/2.6)
Author: Selva Nair Date: Mon May 15 22:42:32 2023 -0400
Correctly handle Unicode names for exit event
Signed-off-by: Selva Nair <[email protected]...>
Acked-by: Lev Stipakov <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg26666.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Quoted 5 lines · Gert Doering
Explanation makes sense, though it's only relevant for "outside openvpn GUI" use cases. But I look forward to a submission of "openvpn windows CLI" :-)
Test compiled on MinGW. Does our GH windows test setup use the event mechanism? Or "classic signals"?
Neither, it uses the GUI CLI :)
See https://github.com/OpenVPN/openvpn-windows-test/blob/master/Start-LocalTest.ps1#L342
Regards,
Signature · 1 line
Frank Lichtenheld