Commit 53a065ae authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

crypt32: Fix key name null termination (Coverity).

parent 19d29f3c
......@@ -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));
}
......
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