Skip to content

Commit

Permalink
mock-pkcs11: remove dead code
Browse files Browse the repository at this point in the history
Coverity noticed we have some unreachable code in mock-pkcs11.c.

At first I thought that was OK, because we have large portions of this
file intentionally unimplemented, but these are just bugs to be removed.

Reported upstream as:

Pkcs11Interop/pkcs11-mock#2
Pkcs11Interop/pkcs11-mock#3
  • Loading branch information
mcatanzaro authored and TingPing committed May 4, 2021
1 parent f587fe9 commit 2d37fba
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions tls/tests/mock-pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ CK_DEFINE_FUNCTION(CK_RV, C_GetTokenInfo)(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR p
pInfo->ulMaxSessionCount = token.ulMaxSessionCount;
pInfo->ulSessionCount = (CK_TRUE == pkcs11_mock_session_opened) ? 1 : 0;
pInfo->ulMaxRwSessionCount = token.ulMaxRwSessionCount;
pInfo->ulRwSessionCount = ((CK_TRUE == pkcs11_mock_session_opened) && ((CKS_RO_PUBLIC_SESSION != pkcs11_mock_session_state) || (CKS_RO_USER_FUNCTIONS != pkcs11_mock_session_state))) ? 1 : 0;
pInfo->ulRwSessionCount = (CK_TRUE == pkcs11_mock_session_opened) ? 1 : 0;
pInfo->ulMaxPinLen = token.ulMaxPinLen;
pInfo->ulMinPinLen = token.ulMinPinLen;
pInfo->ulTotalPublicMemory = token.ulTotalPublicMemory;
Expand Down Expand Up @@ -946,8 +946,6 @@ CK_DEFINE_FUNCTION(CK_RV, C_CreateObject)(CK_SESSION_HANDLE hSession, CK_ATTRIBU

CK_DEFINE_FUNCTION(CK_RV, C_CopyObject)(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phNewObject)
{
CK_ULONG i = 0;

if (CK_FALSE == pkcs11_mock_initialized)
return CKR_CRYPTOKI_NOT_INITIALIZED;

Expand All @@ -960,18 +958,6 @@ CK_DEFINE_FUNCTION(CK_RV, C_CopyObject)(CK_SESSION_HANDLE hSession, CK_OBJECT_HA
if (NULL == phNewObject)
return CKR_ARGUMENTS_BAD;

if ((NULL != pTemplate) && (0 >= ulCount))
{
for (i = 0; i < ulCount; i++)
{
if (NULL == pTemplate[i].pValue)
return CKR_ATTRIBUTE_VALUE_INVALID;

if (0 >= pTemplate[i].ulValueLen)
return CKR_ATTRIBUTE_VALUE_INVALID;
}
}

*phNewObject = PKCS11_MOCK_CK_OBJECT_HANDLE_DATA;

return CKR_OK;
Expand Down Expand Up @@ -2799,9 +2785,6 @@ CK_DEFINE_FUNCTION(CK_RV, C_UnwrapKey)(CK_SESSION_HANDLE hSession, CK_MECHANISM_

CK_DEFINE_FUNCTION(CK_RV, C_DeriveKey)(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hBaseKey, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, CK_OBJECT_HANDLE_PTR phKey)
{
CK_ULONG i = 0;


if (CK_FALSE == pkcs11_mock_initialized)
return CKR_CRYPTOKI_NOT_INITIALIZED;

Expand All @@ -2823,18 +2806,6 @@ CK_DEFINE_FUNCTION(CK_RV, C_DeriveKey)(CK_SESSION_HANDLE hSession, CK_MECHANISM_
if (NULL == phKey)
return CKR_ARGUMENTS_BAD;

if ((NULL != pTemplate) && (0 >= ulAttributeCount))
{
for (i = 0; i < ulAttributeCount; i++)
{
if (NULL == pTemplate[i].pValue)
return CKR_ATTRIBUTE_VALUE_INVALID;

if (0 >= pTemplate[i].ulValueLen)
return CKR_ATTRIBUTE_VALUE_INVALID;
}
}

*phKey = PKCS11_MOCK_CK_OBJECT_HANDLE_SECRET_KEY;

return CKR_OK;
Expand Down

0 comments on commit 2d37fba

Please sign in to comment.