Commit 3d69d71e authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

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

parent eb00dbd9
...@@ -490,16 +490,19 @@ static BOOL BinaryToHexW(const BYTE *bin, DWORD nbin, DWORD flags, LPWSTR str, D ...@@ -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];
......
...@@ -366,10 +366,8 @@ static void test_CryptBinaryToString(void) ...@@ -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 { ...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment