From: Selva Nair Date: Sun, 6 Mar 2016 05:22:02 +0000 (-0500) Subject: Use appropriate buffer size for WideCharToMultiByte output in interactive.c X-Git-Tag: v2.4_alpha1~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3654d953;p=thirdparty%2Fopenvpn.git 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 --- 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);