Skip to content

Commit

Permalink
Merge pull request softhsm#494 from blukat29/null-check
Browse files Browse the repository at this point in the history
Check CK_ATTRIBUTE_PTR arguments for NULL_PTR
  • Loading branch information
halderen authored Aug 28, 2019
2 parents 18bf4ee + cea1398 commit de9012e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/SoftHSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,7 @@ CK_RV SoftHSM::C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE
CK_RV SoftHSM::C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
{
if (!isInitialised) return CKR_CRYPTOKI_NOT_INITIALIZED;
if (pTemplate == NULL_PTR && ulCount != 0) return CKR_ARGUMENTS_BAD;

// Get the session
Session* session = (Session*)handleManager->getSession(hSession);
Expand Down Expand Up @@ -5669,6 +5670,7 @@ CK_RV SoftHSM::C_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMecha
if (!isInitialised) return CKR_CRYPTOKI_NOT_INITIALIZED;

if (pMechanism == NULL_PTR) return CKR_ARGUMENTS_BAD;
if (pTemplate == NULL_PTR && ulCount != 0) return CKR_ARGUMENTS_BAD;
if (phKey == NULL_PTR) return CKR_ARGUMENTS_BAD;

// Get the session
Expand Down Expand Up @@ -5820,6 +5822,8 @@ CK_RV SoftHSM::C_GenerateKeyPair
if (!isInitialised) return CKR_CRYPTOKI_NOT_INITIALIZED;

if (pMechanism == NULL_PTR) return CKR_ARGUMENTS_BAD;
if (pPublicKeyTemplate == NULL_PTR && ulPublicKeyAttributeCount != 0) return CKR_ARGUMENTS_BAD;
if (pPrivateKeyTemplate == NULL_PTR && ulPrivateKeyAttributeCount != 0) return CKR_ARGUMENTS_BAD;
if (phPublicKey == NULL_PTR) return CKR_ARGUMENTS_BAD;
if (phPrivateKey == NULL_PTR) return CKR_ARGUMENTS_BAD;

Expand Down
3 changes: 3 additions & 0 deletions src/lib/test/SymmetricAlgorithmTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,9 @@ void SymmetricAlgorithmTests::testNullTemplate()
rv = CRYPTOKI_F_PTR( C_GenerateKey(hSession, &mechanism1, NULL_PTR, 0, &hKey) );
CPPUNIT_ASSERT(rv == CKR_OK);

rv = CRYPTOKI_F_PTR( C_GenerateKey(hSession, &mechanism1, NULL_PTR, 1, &hKey) );
CPPUNIT_ASSERT(rv == CKR_ARGUMENTS_BAD);

rv = CRYPTOKI_F_PTR( C_DestroyObject(hSession, hKey) );
CPPUNIT_ASSERT(rv == CKR_OK);

Expand Down

0 comments on commit de9012e

Please sign in to comment.