Bug 1347975 - coverity fixes for ec cleanup, r=ttaubert
Differential Revision: https://nss-review.dev.mozaws.net/D260
--- a/cmd/ecperf/ecperf.c
+++ b/cmd/ecperf/ecperf.c
@@ -477,17 +477,17 @@ ectest_curve_freebl(ECCurveName curve, i
PORT_Memset(digestData, 0xa5, sizeof(digestData));
digest.data = digestData;
digest.len = sizeof(digestData);
sig.data = sigData;
sig.len = sizeof(sigData);
rv = EC_NewKey(&ecParams, &ecPriv);
if (rv != SECSuccess) {
- return SECFailure;
+ goto cleanup;
}
ecPub.ecParams = ecParams;
ecPub.publicValue = ecPriv->publicValue;
if (ecCurve_map[curve]->usage & KU_KEY_AGREEMENT) {
rv = M_TimeOperation(genericThread, (op_func)ECDH_DeriveWrap, "ECDH_Derive",
ecPriv, &ecPub, NULL, iterations, numThreads, 0, 0, 0, &deriveRate);
if (rv != SECSuccess) {
@@ -510,17 +510,19 @@ ectest_curve_freebl(ECCurveName curve, i
if (rv != SECSuccess) {
goto cleanup;
}
}
cleanup:
SECITEM_FreeItem(&ecEncodedParams, PR_FALSE);
PORT_FreeArena(arena, PR_FALSE);
- PORT_FreeArena(ecPriv->ecParams.arena, PR_FALSE);
+ if (ecPriv) {
+ PORT_FreeArena(ecPriv->ecParams.arena, PR_FALSE);
+ }
return rv;
}
/* Prints help information. */
void
printUsage(char *prog)
{
printf("Usage: %s [-i iterations] [-t threads ] [-ans] [-fp] [-Al]\n"
--- a/lib/freebl/ecl/ecl.c
+++ b/lib/freebl/ecl/ecl.c
@@ -262,41 +262,28 @@ ec_GetNamedCurveParams(const ECCurveName
return ecCurve_map[name];
}
}
/* Construct ECGroup from named parameters. */
ECGroup *
ECGroup_fromName(const ECCurveName name)
{
- ECGroup *group = NULL;
const ECCurveBytes *params = NULL;
- mp_err res = MP_OKAY;
/* This doesn't work with Curve25519 but it's not necessary to. */
PORT_Assert(name != ECCurve25519);
params = ec_GetNamedCurveParams(name);
if (params == NULL) {
- res = MP_UNDEF;
- goto CLEANUP;
+ return NULL;
}
/* construct actual group */
- group = ecgroup_fromName(name, params);
- if (group == NULL) {
- res = MP_UNDEF;
- }
-
-CLEANUP:
- if (group && res != MP_OKAY) {
- ECGroup_free(group);
- return NULL;
- }
- return group;
+ return ecgroup_fromName(name, params);
}
/* Validates an EC public key as described in Section 5.2.2 of X9.62. */
mp_err
ECPoint_validate(const ECGroup *group, const mp_int *px, const mp_int *py)
{
/* 1: Verify that publicValue is not the point at infinity */
/* 2: Verify that the coordinates of publicValue are elements