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>
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)
{