Skip to content

Commit

Permalink
Bug 1273780 - fixing coverity issues in ecperf, r=ttaubert
Browse files Browse the repository at this point in the history
  • Loading branch information
franziskuskiefer committed May 20, 2016
1 parent 3dffcde commit c39b350
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
32 changes: 21 additions & 11 deletions cmd/ecperf/ecperf.c
Expand Up @@ -83,6 +83,9 @@ static SECOidTag ecCurve_oid_map[] = {
SEC_OID_SECG_EC_SECT193R1,
SEC_OID_SECG_EC_SECT193R2,
SEC_OID_SECG_EC_SECT239K1,
SEC_OID_UNKNOWN, /* ECCurve_WTLS_1 */
SEC_OID_UNKNOWN, /* ECCurve_WTLS_8 */
SEC_OID_UNKNOWN, /* ECCurve_WTLS_9 */
SEC_OID_UNKNOWN /* ECCurve_pastLastCurve */
};

Expand Down Expand Up @@ -206,6 +209,12 @@ M_TimeOperation(void (*threadFunc)(void *),
} else {
rv = (*opfunc)(param1, param2, param3);
}
if (rv != SECSuccess) {
PORT_Free(threadIDs);
PORT_Free(threadData);
SECU_PrintError("Error:", op);
return rv;
}
}
total = iters;
} else {
Expand All @@ -228,9 +237,6 @@ M_TimeOperation(void (*threadFunc)(void *),
/* check the status */
total += threadData[i].count;
}

PORT_Free(threadIDs);
PORT_Free(threadData);
}

totalTime = PR_Now() - startTime;
Expand All @@ -243,6 +249,9 @@ M_TimeOperation(void (*threadFunc)(void *),
*rate = ((double)total) / dUserTime;
}
}
PORT_Free(threadIDs);
PORT_Free(threadData);

return SECSuccess;
}

Expand Down Expand Up @@ -392,12 +401,13 @@ PKCS11_Sign(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE *hKey,
printf("Sign Failed CK_RV=0x%x\n", (int)crv);
return SECFailure;
}
crv = NSC_Sign(session, digest->data, digest->len, sig->data,
(CK_ULONG_PTR)&sig->len);
CK_ULONG sigLen = sig->len;
crv = NSC_Sign(session, digest->data, digest->len, sig->data, &sigLen);
if (crv != CKR_OK) {
printf("Sign Failed CK_RV=0x%x\n", (int)crv);
return SECFailure;
}
sig->len = (CK_ULONG)sigLen;
return SECSuccess;
}

Expand Down Expand Up @@ -609,22 +619,22 @@ ectest_curve_freebl(ECCurveName curve, int iterations, int numThreads)
ecPub.ecParams = ecParams;
ecPub.publicValue = ecPriv->publicValue;

M_TimeOperation(genericThread, (op_func)ECDH_DeriveWrap, "ECDH_Derive",
ecPriv, &ecPub, NULL, iterations, numThreads, 0, 0, 0, &deriveRate);
rv = M_TimeOperation(genericThread, (op_func)ECDH_DeriveWrap, "ECDH_Derive",
ecPriv, &ecPub, NULL, iterations, numThreads, 0, 0, 0, &deriveRate);
if (rv != SECSuccess) {
goto cleanup;
}
M_TimeOperation(genericThread, (op_func)ECDSA_SignDigest, "ECDSA_Sign",
ecPriv, &sig, &digest, iterations, numThreads, 0, 0, 1, &signRate);
rv = M_TimeOperation(genericThread, (op_func)ECDSA_SignDigest, "ECDSA_Sign",
ecPriv, &sig, &digest, iterations, numThreads, 0, 0, 1, &signRate);
if (rv != SECSuccess)
goto cleanup;
printf(" ECDHE max rate = %.2f\n", (deriveRate + signRate) / 4.0);
rv = ECDSA_SignDigest(ecPriv, &sig, &digest);
if (rv != SECSuccess) {
goto cleanup;
}
M_TimeOperation(genericThread, (op_func)ECDSA_VerifyDigest, "ECDSA_Verify",
&ecPub, &sig, &digest, iterations, numThreads, 0, 0, 0, NULL);
rv = M_TimeOperation(genericThread, (op_func)ECDSA_VerifyDigest, "ECDSA_Verify",
&ecPub, &sig, &digest, iterations, numThreads, 0, 0, 0, NULL);
if (rv != SECSuccess) {
goto cleanup;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/softoken/pkcs11c.c
Expand Up @@ -2069,6 +2069,9 @@ sftk_InitCBCMac(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,

switch (pMechanism->mechanism) {
case CKM_RC2_MAC_GENERAL:
if (!pMechanism->pParameter) {
return CKR_MECHANISM_PARAM_INVALID;
}
mac_bytes =
((CK_RC2_MAC_GENERAL_PARAMS *)pMechanism->pParameter)->ulMacLength;
/* fall through */
Expand Down

0 comments on commit c39b350

Please sign in to comment.