mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2025-08-06 09:39:44 +08:00
Fix memory leak in transport_mbedtls_pkcs11.c
This commit is contained in:

committed by
Paul Bartell

parent
1fc1e01fb6
commit
0ca1ec8861
@ -387,56 +387,6 @@ CK_RV xPKCS11_initMbedtlsPkContext( mbedtls_pk_context * pxMbedtlsPkCtx,
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
int lPKCS11PkMbedtlsCloseSessionAndFree( mbedtls_pk_context * pxMbedtlsPkCtx )
|
||||
{
|
||||
CK_RV xResult = CKR_OK;
|
||||
P11PkCtx_t * pxP11Ctx = NULL;
|
||||
CK_FUNCTION_LIST_PTR pxFunctionList = NULL;
|
||||
|
||||
configASSERT( pxMbedtlsPkCtx );
|
||||
|
||||
if( pxMbedtlsPkCtx )
|
||||
{
|
||||
if( pxMbedtlsPkCtx->pk_info->type == MBEDTLS_PK_ECKEY )
|
||||
{
|
||||
pxP11Ctx = &( ( ( P11EcDsaCtx_t * ) ( pxMbedtlsPkCtx->pk_ctx ) )->xP11PkCtx );
|
||||
}
|
||||
else if( pxMbedtlsPkCtx->pk_info->type == MBEDTLS_PK_RSA )
|
||||
{
|
||||
pxP11Ctx = &( ( ( P11RsaCtx_t * ) ( pxMbedtlsPkCtx->pk_ctx ) )->xP11PkCtx );
|
||||
}
|
||||
else
|
||||
{
|
||||
pxP11Ctx = NULL;
|
||||
xResult = CKR_FUNCTION_FAILED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
xResult = CKR_FUNCTION_FAILED;
|
||||
}
|
||||
|
||||
if( xResult == CKR_OK )
|
||||
{
|
||||
xResult = C_GetFunctionList( &pxFunctionList );
|
||||
}
|
||||
|
||||
if( xResult == CKR_OK )
|
||||
{
|
||||
configASSERT( pxFunctionList );
|
||||
xResult = pxFunctionList->C_CloseSession( pxP11Ctx->xSessionHandle );
|
||||
}
|
||||
|
||||
if( xResult == CKR_OK )
|
||||
{
|
||||
pxP11Ctx->xSessionHandle = CK_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
return( xResult == CKR_OK ? 0 : -1 );
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
int lPKCS11RandomCallback( void * pvCtx,
|
||||
unsigned char * pucOutput,
|
||||
size_t uxLen )
|
||||
|
@ -46,15 +46,6 @@ CK_RV xPKCS11_initMbedtlsPkContext( mbedtls_pk_context * pxMbedtlsPkCtx,
|
||||
CK_SESSION_HANDLE xSessionHandle,
|
||||
CK_OBJECT_HANDLE xPkHandle );
|
||||
|
||||
/**
|
||||
* @brief Close the PKCS11 session and free the relevant pk context.
|
||||
*
|
||||
* @param pxMbedtlsPkCtx Pointer to the mbedtls_pk_context to free
|
||||
* @return 0 on success
|
||||
* @return A negative number on failure
|
||||
*/
|
||||
int lPKCS11PkMbedtlsCloseSessionAndFree( mbedtls_pk_context * pxMbedtlsPkCtx );
|
||||
|
||||
/**
|
||||
* @brief Callback to generate random data with the PKCS11 module.
|
||||
*
|
||||
@ -68,6 +59,4 @@ int lPKCS11RandomCallback( void * pvCtx,
|
||||
unsigned char * pucOutput,
|
||||
size_t uxLen );
|
||||
|
||||
|
||||
|
||||
#endif /* MBEDTLS_PK_PKCS11_H */
|
||||
|
@ -179,13 +179,6 @@ static CK_RV readCertificateIntoContext( SSLContext_t * pSslContext,
|
||||
static CK_RV initializeClientKeys( SSLContext_t * pxCtx,
|
||||
const char * pcLabelName );
|
||||
|
||||
/**
|
||||
* @brief Stub function to satisfy mbedtls checks before sign operations
|
||||
*
|
||||
* @return 1.
|
||||
*/
|
||||
int canDoStub( mbedtls_pk_type_t type );
|
||||
|
||||
/**
|
||||
* @brief Sign a cryptographic hash with the private key.
|
||||
*
|
||||
@ -237,8 +230,7 @@ static void sslContextFree( SSLContext_t * pSslContext )
|
||||
mbedtls_x509_crt_free( &( pSslContext->clientCert ) );
|
||||
mbedtls_ssl_config_free( &( pSslContext->config ) );
|
||||
|
||||
|
||||
( void ) lPKCS11PkMbedtlsCloseSessionAndFree( &( pSslContext->privKey ) );
|
||||
mbedtls_pk_free( &( pSslContext->privKey ) );
|
||||
|
||||
pSslContext->pxP11FunctionList->C_CloseSession( pSslContext->xP11Session );
|
||||
}
|
||||
|
Reference in New Issue
Block a user