Skip to content

Commit 531a733

Browse files
committed
Fix cbmc
Signed-off-by: Gaurav Aggarwal <[email protected]>
1 parent 473f865 commit 531a733

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

source/portable/mbedtls/core_pkcs11_mbedtls.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,7 @@ CK_DECLARE_FUNCTION( CK_RV, C_GetAttributeValue )( CK_SESSION_HANDLE hSession,
32263226
mbedtls_x509_crt xMbedX509Context = { 0 };
32273227
mbedtls_pk_type_t xKeyType;
32283228
const mbedtls_ecp_keypair * pxKeyPair;
3229+
const mbedtls_rsa_context * pxRsaContext;
32293230
CK_KEY_TYPE xPkcsKeyType = ( CK_KEY_TYPE ) ~0UL;
32303231
CK_OBJECT_CLASS xClass = ~0UL;
32313232
CK_BYTE_PTR pxObjectValue = NULL;
@@ -3534,8 +3535,6 @@ CK_DECLARE_FUNCTION( CK_RV, C_GetAttributeValue )( CK_SESSION_HANDLE hSession,
35343535
case CKA_EXPONENT_2:
35353536
case CKA_COEFFICIENT:
35363537
{
3537-
mbedtls_rsa_context * pxRsaContext = ( mbedtls_rsa_context * ) xKeyContext.pk_ctx;
3538-
35393538
if( pTemplate[ iAttrib ].pValue == NULL )
35403539
{
35413540
pTemplate[ iAttrib ].ulValueLen = sizeof( mbedtls_mpi );
@@ -3544,8 +3543,18 @@ CK_DECLARE_FUNCTION( CK_RV, C_GetAttributeValue )( CK_SESSION_HANDLE hSession,
35443543
{
35453544
if( pTemplate[ iAttrib ].ulValueLen == sizeof( mbedtls_mpi ) )
35463545
{
3547-
xResult = prvGetAttributesFromRsaContext( &( pTemplate[ iAttrib ] ),
3548-
pxRsaContext );
3546+
pxRsaContext = ( mbedtls_rsa_context * ) xKeyContext.pk_ctx;
3547+
3548+
if( pxRsaContext != NULL )
3549+
{
3550+
xResult = prvGetAttributesFromRsaContext( &( pTemplate[ iAttrib ] ),
3551+
pxRsaContext );
3552+
}
3553+
else
3554+
{
3555+
xResult = CKR_FUNCTION_FAILED;
3556+
pTemplate[ iAttrib ].ulValueLen = CK_UNAVAILABLE_INFORMATION;
3557+
}
35493558
}
35503559
else
35513560
{

0 commit comments

Comments
 (0)