Fixed smartcard_convert_string_list with 0 length

This commit is contained in:
Armin Novak 2021-03-03 11:39:55 +01:00 committed by akallabeth
parent 10a595164d
commit c890db30c7

View File

@ -351,8 +351,11 @@ static char* smartcard_convert_string_list(const void* in, size_t bytes, BOOL un
if (unicode)
{
length = (bytes / 2);
if (ConvertFromUnicode(CP_UTF8, 0, string.wz, (int)length, &mszA, 0, NULL, NULL) !=
length = (bytes / sizeof(WCHAR)) - 1;
mszA = (char*)calloc(length + 1, sizeof(WCHAR));
if (!mszA)
return NULL;
if (ConvertFromUnicode(CP_UTF8, 0, string.wz, (int)length, &mszA, length + 1, NULL, NULL) !=
(int)length)
{
free(mszA);
@ -362,10 +365,11 @@ static char* smartcard_convert_string_list(const void* in, size_t bytes, BOOL un
else
{
length = bytes;
mszA = (char*)malloc(length);
mszA = (char*)calloc(length, sizeof(char));
if (!mszA)
return NULL;
CopyMemory(mszA, string.sz, length);
CopyMemory(mszA, string.sz, length - 1);
mszA[length - 1] = '\0';
}
for (index = 0; index < length - 1; index++)