Skip to content

Commit

Permalink
Bug 1304337 - fix ec coverity issues, r=ttaubert
Browse files Browse the repository at this point in the history
--HG--
extra : rebase_source : 947263c86d1af5a5186a7dc8aed45cd5e7615bd3
extra : amend_source : 770db3f1c44f52ecdadf273ce8f9abee5b7df71d
extra : histedit_source : e30c25e40e2ea179f42284a1a4a86f568126b3e2
  • Loading branch information
franziskuskiefer committed Sep 22, 2016
1 parent dd57a5d commit beb3c97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions cmd/ectest/ectest.c
Expand Up @@ -149,6 +149,8 @@ ectest_ecdh_kat(ECDH_KAT *kat)
genenc[0] = '0';
genenc[1] = '4';
genenc[2] = '\0';
PORT_Assert(PR_ARRAY_SIZE(genenc) >= PORT_Strlen(ecCurve_map[curve]->genx));
PORT_Assert(PR_ARRAY_SIZE(genenc) >= PORT_Strlen(ecCurve_map[curve]->geny));
strcat(genenc, ecCurve_map[curve]->genx);
strcat(genenc, ecCurve_map[curve]->geny);
hexString2SECItem(arena, &ecParams.base, genenc);
Expand Down Expand Up @@ -185,8 +187,14 @@ ectest_ecdh_kat(ECDH_KAT *kat)
rv = SECFailure;
goto cleanup;
}
SECITEM_CopyItem(ecParams.arena, &theirKey, &ecPriv->privateValue);
SECITEM_CopyItem(ecParams.arena, &ecPriv->privateValue, &derived);
rv = SECITEM_CopyItem(ecParams.arena, &theirKey, &ecPriv->privateValue);
if (rv != SECSuccess) {
goto cleanup;
}
rv = SECITEM_CopyItem(ecParams.arena, &ecPriv->privateValue, &derived);
if (rv != SECSuccess) {
goto cleanup;
}
SECITEM_FreeItem(&derived, PR_FALSE);
}

Expand All @@ -204,7 +212,9 @@ ectest_ecdh_kat(ECDH_KAT *kat)
if (ecPriv) {
PORT_FreeArena(ecPriv->ecParams.arena, PR_FALSE);
}
SECITEM_FreeItem(&derived, PR_FALSE);
if (derived.data) {
SECITEM_FreeItem(&derived, PR_FALSE);
}
return rv;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/freebl/ec.c
Expand Up @@ -459,8 +459,8 @@ EC_ValidatePublicKey(ECParams *ecParams, SECItem *publicValue)
const ECMethod *method = ec_get_method_from_name(ecParams->name);
if (method == NULL || method->validate == NULL) {
/* unknown curve */
rv = SECFailure;
goto cleanup;
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return SECFailure;
}
return method->validate(publicValue);
}
Expand Down Expand Up @@ -570,7 +570,7 @@ ECDH_Derive(SECItem *publicValue,
if (ecParams->fieldID.type == ec_field_plain) {
const ECMethod *method;
memset(derivedSecret, 0, sizeof(*derivedSecret));
SECITEM_AllocItem(NULL, derivedSecret, ecParams->pointSize);
derivedSecret = SECITEM_AllocItem(NULL, derivedSecret, ecParams->pointSize);
if (derivedSecret == NULL) {
PORT_SetError(SEC_ERROR_NO_MEMORY);
return SECFailure;
Expand Down

0 comments on commit beb3c97

Please sign in to comment.