From 3654d953eb0bf40fb8c9e1fbaa3de1dd898dcbab Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Sun, 6 Mar 2016 00:22:02 -0500 Subject: [PATCH] Use appropriate buffer size for WideCharToMultiByte output in interactive.c A widechar can potentially take more than 2 bytes in UTF-8. Signed-off-by: Selva Nair Acked-by: Gert Doering Message-Id: <1457241722-23433-1-git-send-email-selva.nair@gmail.com> URL: http://article.gmane.org/gmane.network.openvpn.devel/11318 Signed-off-by: Gert Doering --- src/openvpnserv/interactive.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 39397d12a..6a7227b7e 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -1063,17 +1063,16 @@ RunOpenvpn (LPVOID p) CloseHandleEx (&stdin_read); CloseHandleEx (&svc_pipe); - DWORD input_size = wcslen (sud.std_input) * 2; - if (input_size) + DWORD input_size = WideCharToMultiByte (CP_UTF8, 0, sud.std_input, -1, NULL, 0, NULL, NULL); + LPSTR input = NULL; + if (input_size && (input = malloc (input_size))) { DWORD written; - LPSTR input = malloc (input_size); WideCharToMultiByte (CP_UTF8, 0, sud.std_input, -1, input, input_size, NULL, NULL); WriteFile (stdin_write, input, strlen (input), &written, NULL); free (input); } - while (TRUE) { DWORD bytes = PeekNamedPipeAsync (ovpn_pipe, 1, &exit_event); -- 2.47.2