]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
iservice: check return value of MultiByteToWideChar
authorHeiko Hund <heiko@ist.eigentlich.net>
Thu, 30 Oct 2025 19:47:31 +0000 (20:47 +0100)
committerGert Doering <gert@greenie.muc.de>
Thu, 30 Oct 2025 21:06:43 +0000 (22:06 +0100)
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 <contact@joshua.hu>
Change-Id: I92804da010bab36cd0326759c04f955f2bda74de
Signed-off-by: Heiko Hund <heiko@ist.eigentlich.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
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 <gert@greenie.muc.de>
src/openvpnserv/common.c

index e975cc758cfb3cba7ff7133a9934fe7b4518101b..d25d9c0e92c91cf4457e09307db9daedfcc67c07 100644 (file)
@@ -276,6 +276,10 @@ wchar_t *
 utf8to16_size(const char *utf8, int size)
 {
     int n = MultiByteToWideChar(CP_UTF8, 0, utf8, size, NULL, 0);
+    if (n == 0)
+    {
+        return NULL;
+    }
     wchar_t *utf16 = malloc(n * sizeof(wchar_t));
     if (!utf16)
     {