fix bug in cng cipher keyobject processing

KeyObject for cipher symmetric key was being allocated improperly due to
an error in getting the key object size.  Also added code to free
keyobject in the event of a key creation failure.
This commit is contained in:
dkulwin 2015-10-31 12:06:10 -05:00
parent fad3c4ffc6
commit 3ab9c8f055

View File

@ -286,7 +286,7 @@ unsigned int cng_cipher_init(PSSH_CNG_CIPHER_CTX x, const unsigned char *key, un
status = BCryptGetProperty(
hAlg,
BCRYPT_OBJECT_LENGTH,
(PBYTE)cbKeyObject,
(PBYTE)&cbKeyObject,
sizeof(DWORD),
&cbData,
0);
@ -305,11 +305,15 @@ unsigned int cng_cipher_init(PSSH_CNG_CIPHER_CTX x, const unsigned char *key, un
}
BCryptCloseAlgorithmProvider(hAlg, 0);
// if we got an error along the way, free up the iv
// if we got an error along the way, free up the iv and key object
if (status != S_OK && x->pbIV)
{
HeapFree(GetProcessHeap(), 0, x->pbIV);
}
if (status != S_OK && x->pKeyObject)
{
HeapFree(GetProcessHeap(), 0, x->pKeyObject);
}
}
return status;
}