crypt32: Fix CryptBinaryToStringW() to return required length properly.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2020-02-11 12:25:40 +03:00 committed by Alexandre Julliard
parent eb00dbd913
commit 3d69d71e9e
2 changed files with 8 additions and 8 deletions

View File

@ -490,16 +490,19 @@ static BOOL BinaryToHexW(const BYTE *bin, DWORD nbin, DWORD flags, LPWSTR str, D
needed = 2; needed = 2;
needed += nbin * 2 + 1; needed += nbin * 2 + 1;
if (!str)
{
*nstr = needed;
return TRUE;
}
if (needed > *nstr) if (needed > *nstr)
{ {
SetLastError(ERROR_MORE_DATA); SetLastError(ERROR_MORE_DATA);
return FALSE; return FALSE;
} }
*nstr = needed;
if (!str)
return TRUE;
while (nbin--) while (nbin--)
{ {
*str++ = hex[(*bin >> 4) & 0xf]; *str++ = hex[(*bin >> 4) & 0xf];

View File

@ -366,10 +366,8 @@ static void test_CryptBinaryToString(void)
/* Systems that don't support HEXRAW format convert to BASE64 instead - 3 bytes in -> 4 chars + crlf + 1 null out. */ /* Systems that don't support HEXRAW format convert to BASE64 instead - 3 bytes in -> 4 chars + crlf + 1 null out. */
strLen = 0; strLen = 0;
ret = CryptBinaryToStringW(input, 3, CRYPT_STRING_HEXRAW, NULL, &strLen); ret = CryptBinaryToStringW(input, 3, CRYPT_STRING_HEXRAW, NULL, &strLen);
todo_wine {
ok(ret, "Failed to get string length.\n"); ok(ret, "Failed to get string length.\n");
ok(strLen == 9 || broken(strLen == 7), "Unexpected string length %d.\n", strLen); ok(strLen == 9 || broken(strLen == 7), "Unexpected string length %d.\n", strLen);
}
if (strLen == 7) if (strLen == 7)
{ {
win_skip("CryptBinaryToString(HEXRAW) not supported\n"); win_skip("CryptBinaryToString(HEXRAW) not supported\n");
@ -383,10 +381,9 @@ todo_wine {
{ {
strLen = 0; strLen = 0;
ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i], NULL, &strLen); ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i], NULL, &strLen);
todo_wine {
ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError()); ok(ret, "CryptBinaryToStringW failed: %d\n", GetLastError());
ok(strLen > 0, "Unexpected string length.\n"); ok(strLen > 0, "Unexpected string length.\n");
}
strLen = ~0; strLen = ~0;
ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i], ret = CryptBinaryToStringW(input, sizeof(input), CRYPT_STRING_HEXRAW|flags[i],
NULL, &strLen); NULL, &strLen);