framework-pkcs15: fixed memory leak when encoding pubkey

This commit is contained in:
Frank Morgner 2015-04-30 06:46:31 +02:00 committed by Viktor Tarasov
parent e84951a5bf
commit e338b7c1ab
1 changed files with 11 additions and 1 deletions

View File

@ -3972,7 +3972,17 @@ pkcs15_pubkey_get_attribute(struct sc_pkcs11_session *session, void *object, CK_
if (sc_pkcs15_encode_pubkey(context, pubkey->pub_data, &value, &len))
return sc_to_cryptoki_error(SC_ERROR_INTERNAL, "C_GetAttributeValue");
check_attribute_buffer(attr, len);
if (attr->pValue == NULL_PTR) {
attr->ulValueLen = len;
free(value);
return CKR_OK;
}
if (attr->ulValueLen < len) {
attr->ulValueLen = len;
free(value);
return CKR_BUFFER_TOO_SMALL;
}
attr->ulValueLen = len;
memcpy(attr->pValue, value, len);
free(value);