From 531a7331b16d47cc86a7667f26f5b91901ddcb8a Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Tue, 15 Oct 2024 09:58:50 +0000 Subject: [PATCH] Fix cbmc Signed-off-by: Gaurav Aggarwal --- source/portable/mbedtls/core_pkcs11_mbedtls.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/source/portable/mbedtls/core_pkcs11_mbedtls.c b/source/portable/mbedtls/core_pkcs11_mbedtls.c index 871f077e..2607d2c3 100644 --- a/source/portable/mbedtls/core_pkcs11_mbedtls.c +++ b/source/portable/mbedtls/core_pkcs11_mbedtls.c @@ -3226,6 +3226,7 @@ CK_DECLARE_FUNCTION( CK_RV, C_GetAttributeValue )( CK_SESSION_HANDLE hSession, mbedtls_x509_crt xMbedX509Context = { 0 }; mbedtls_pk_type_t xKeyType; const mbedtls_ecp_keypair * pxKeyPair; + const mbedtls_rsa_context * pxRsaContext; CK_KEY_TYPE xPkcsKeyType = ( CK_KEY_TYPE ) ~0UL; CK_OBJECT_CLASS xClass = ~0UL; CK_BYTE_PTR pxObjectValue = NULL; @@ -3534,8 +3535,6 @@ CK_DECLARE_FUNCTION( CK_RV, C_GetAttributeValue )( CK_SESSION_HANDLE hSession, case CKA_EXPONENT_2: case CKA_COEFFICIENT: { - mbedtls_rsa_context * pxRsaContext = ( mbedtls_rsa_context * ) xKeyContext.pk_ctx; - if( pTemplate[ iAttrib ].pValue == NULL ) { pTemplate[ iAttrib ].ulValueLen = sizeof( mbedtls_mpi ); @@ -3544,8 +3543,18 @@ CK_DECLARE_FUNCTION( CK_RV, C_GetAttributeValue )( CK_SESSION_HANDLE hSession, { if( pTemplate[ iAttrib ].ulValueLen == sizeof( mbedtls_mpi ) ) { - xResult = prvGetAttributesFromRsaContext( &( pTemplate[ iAttrib ] ), - pxRsaContext ); + pxRsaContext = ( mbedtls_rsa_context * ) xKeyContext.pk_ctx; + + if( pxRsaContext != NULL ) + { + xResult = prvGetAttributesFromRsaContext( &( pTemplate[ iAttrib ] ), + pxRsaContext ); + } + else + { + xResult = CKR_FUNCTION_FAILED; + pTemplate[ iAttrib ].ulValueLen = CK_UNAVAILABLE_INFORMATION; + } } else {