crypt32: Fix key name null termination (Coverity).

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2015-11-23 15:29:06 +03:00 committed by Alexandre Julliard
parent 19d29f3ca5
commit 53a065ae0a
1 changed files with 6 additions and 10 deletions

View File

@ -769,7 +769,7 @@ struct KeynameKeeper
{
WCHAR buf[10]; /* big enough for L"GivenName" */
LPWSTR keyName; /* usually = buf, but may be allocated */
DWORD keyLen;
DWORD keyLen; /* full available buffer size in WCHARs */
};
static void CRYPT_InitializeKeynameKeeper(struct KeynameKeeper *keeper)
@ -795,17 +795,13 @@ static void CRYPT_KeynameKeeperFromTokenW(struct KeynameKeeper *keeper,
{
DWORD len = key->end - key->start;
if (len > keeper->keyLen)
if (len >= keeper->keyLen)
{
if (keeper->keyName == keeper->buf)
keeper->keyName = CryptMemAlloc(len * sizeof(WCHAR));
else
keeper->keyName = CryptMemRealloc(keeper->keyName,
len * sizeof(WCHAR));
keeper->keyLen = len;
CRYPT_FreeKeynameKeeper( keeper );
keeper->keyLen = len + 1;
keeper->keyName = CryptMemAlloc(keeper->keyLen * sizeof(WCHAR));
}
memcpy(keeper->keyName, key->start, (key->end - key->start) *
sizeof(WCHAR));
memcpy(keeper->keyName, key->start, len * sizeof(WCHAR));
keeper->keyName[len] = '\0';
TRACE("Keyname is %s\n", debugstr_w(keeper->keyName));
}