pkcs11: check arguments in get_bignum_bits() procedure

t451: segmentation fault when getting public key bits number
This commit is contained in:
Viktor Tarasov 2012-11-12 16:46:25 +01:00
parent bd86063835
commit 6c051f8490
1 changed files with 5 additions and 2 deletions

View File

@ -4179,11 +4179,14 @@ get_bignum_bits(sc_pkcs15_bignum_t *bn, CK_ATTRIBUTE_PTR attr)
{
CK_ULONG bits, mask;
if (!bn || !bn->len || !bn->data)
return CKR_DEVICE_ERROR;
bits = bn->len * 8;
for (mask = 0x80; mask; mask >>= 1, bits--) {
for (mask = 0x80; mask; mask >>= 1, bits--)
if (bn->data[0] & mask)
break;
}
check_attribute_buffer(attr, sizeof(bits));
*(CK_ULONG *) attr->pValue = bits;
return CKR_OK;