Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Initialize Variables. Fix Potential Null Reference in xFindObjectWith… #1926

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions libraries/freertos_plus/standard/pkcs11/src/iot_pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CK_RV prvOpenSession( CK_SESSION_HANDLE * pxSession,
CK_RV xGetSlotList( CK_SLOT_ID ** ppxSlotId,
CK_ULONG * pxSlotCount )
{
CK_RV xResult;
CK_RV xResult = CKR_OK;
CK_FUNCTION_LIST_PTR pxFunctionList;
CK_SLOT_ID * pxSlotId = NULL;

Expand Down Expand Up @@ -125,9 +125,9 @@ CK_RV xGetSlotList( CK_SLOT_ID ** ppxSlotId,

CK_RV xInitializePKCS11( void )
{
CK_RV xResult;
CK_FUNCTION_LIST_PTR pxFunctionList;
CK_C_INITIALIZE_ARGS xInitArgs;
CK_RV xResult = CKR_OK;
CK_FUNCTION_LIST_PTR pxFunctionList = NULL;
CK_C_INITIALIZE_ARGS xInitArgs = { 0 };

xInitArgs.CreateMutex = NULL;
xInitArgs.DestroyMutex = NULL;
Expand All @@ -151,9 +151,9 @@ CK_RV xInitializePKCS11( void )

CK_RV xInitializePkcs11Token( void )
{
CK_RV xResult;
CK_RV xResult = CKR_OK;

CK_FUNCTION_LIST_PTR pxFunctionList;
CK_FUNCTION_LIST_PTR pxFunctionList = NULL;
CK_SLOT_ID * pxSlotId = NULL;
CK_ULONG xSlotCount;
CK_FLAGS xTokenFlags = 0;
Expand Down Expand Up @@ -223,10 +223,10 @@ CK_RV xInitializePkcs11Token( void )

CK_RV xInitializePkcs11Session( CK_SESSION_HANDLE * pxSession )
{
CK_RV xResult;
CK_RV xResult = CKR_OK;
CK_SLOT_ID * pxSlotId = NULL;
CK_FUNCTION_LIST_PTR pxFunctionList;
CK_ULONG xSlotCount;
CK_FUNCTION_LIST_PTR pxFunctionList = NULL;
CK_ULONG xSlotCount = 0;

xResult = C_GetFunctionList( &pxFunctionList );

Expand Down Expand Up @@ -286,18 +286,24 @@ CK_RV xFindObjectWithLabelAndClass( CK_SESSION_HANDLE xSession,
CK_ULONG ulCount = 0;
CK_BBOOL xFindInit = CK_FALSE;
CK_FUNCTION_LIST_PTR pxFunctionList;
CK_ATTRIBUTE xTemplate[ 2 ] =
{
{ CKA_LABEL, ( char * ) pcLabelName, strlen( pcLabelName ) },
{ CKA_CLASS, &xClass, sizeof( CK_OBJECT_CLASS ) }
};

xResult = C_GetFunctionList( &pxFunctionList );
CK_ATTRIBUTE xTemplate[ 2 ] = { 0 };

if( ( pcLabelName == NULL ) || ( pxHandle == NULL ) )
{
xResult = CKR_ARGUMENTS_BAD;
}
else
{
xTemplate[ 0 ].type = CKA_LABEL;
xTemplate[ 0 ].pValue = ( char * ) pcLabelName;
xTemplate[ 0 ].ulValueLen = strlen( pcLabelName );

xTemplate[ 1 ].type = CKA_CLASS;
xTemplate[ 1 ].pValue = &xClass;
xTemplate[ 1 ].ulValueLen = sizeof( CK_OBJECT_CLASS );

xResult = C_GetFunctionList( &pxFunctionList );
}

/* Initialize the FindObject state in the underlying PKCS #11 module based
* on the search template provided by the caller. */
Expand Down