Bug 1347975 - coverity fixes for ec cleanup, r=ttaubert
authorFranziskus Kiefer <franziskuskiefer@gmail.com>
Mon, 20 Mar 2017 09:15:10 +0100
changeset 13228 8e85df1972f9fa2c34bac40bd7d65ad2591c377f
parent 13227 d621b1e53054ea654f187990e959233c9f63b249
child 13229 42d76657dc9501e520514a69c464bee9377ce49c
push id2098
push userfranziskuskiefer@gmail.com
push dateMon, 20 Mar 2017 10:36:54 +0000
reviewersttaubert
bugs1347975
Bug 1347975 - coverity fixes for ec cleanup, r=ttaubert Differential Revision: https://nss-review.dev.mozaws.net/D260
cmd/ecperf/ecperf.c
lib/freebl/ecl/ecl.c
--- 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