From 5b5fdb05d969abc0be7a701c752821299cb98d5e Mon Sep 17 00:00:00 2001 From: Heiko Hund Date: Thu, 30 Oct 2025 20:47:31 +0100 Subject: [PATCH] iservice: check return value of MultiByteToWideChar If the first call to MultiByteToWideChar returns 0, something must have failed, because it returns the required buffer size including the terminating zero. When it does return 0, just return NULL and indicate that the call to utf8to16(_size) failed. Found by ZeroPath. Reported-By: Joshua Rogers Change-Id: I92804da010bab36cd0326759c04f955f2bda74de Signed-off-by: Heiko Hund Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1306 Message-Id: <20251030194736.2151-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34071.html Signed-off-by: Gert Doering (cherry picked from commit fdd4072541ba52e297c19672d3b1e7021d14bc91) --- src/openvpnserv/common.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index feaae199..c4c0ac63 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -293,6 +293,10 @@ wchar_t * utf8to16(const char *utf8) { int n = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0); + if (n == 0) + { + return NULL; + } wchar_t *utf16 = malloc(n * sizeof(wchar_t)); if (!utf16) {