Fix scan-build warning. Updated "side" variable failure case to return proper error code.

This commit is contained in:
David Garske
2016-12-06 13:12:18 -08:00
parent 4dd393077f
commit 5c59ccdeb9

View File

@@ -1711,8 +1711,8 @@ static INLINE int myEccSharedSecret(WOLFSSL* ssl, ecc_key* otherKey,
int side, void* ctx) int side, void* ctx)
{ {
int ret; int ret;
ecc_key* privKey; ecc_key* privKey = NULL;
ecc_key* pubKey; ecc_key* pubKey = NULL;
ecc_key tmpKey; ecc_key tmpKey;
(void)ssl; (void)ssl;
@@ -1726,10 +1726,12 @@ static INLINE int myEccSharedSecret(WOLFSSL* ssl, ecc_key* otherKey,
/* for client: create and export public key */ /* for client: create and export public key */
if (side == WOLFSSL_CLIENT_END) { if (side == WOLFSSL_CLIENT_END) {
WC_RNG rng; WC_RNG rng;
ret = wc_InitRng(&rng);
if (ret == 0) {
privKey = &tmpKey; privKey = &tmpKey;
pubKey = otherKey; pubKey = otherKey;
ret = wc_InitRng(&rng);
if (ret == 0) {
ret = wc_ecc_make_key_ex(&rng, 0, privKey, otherKey->dp->id); ret = wc_ecc_make_key_ex(&rng, 0, privKey, otherKey->dp->id);
if (ret == 0) if (ret == 0)
ret = wc_ecc_export_x963(privKey, pubKeyDer, pubKeySz); ret = wc_ecc_export_x963(privKey, pubKeyDer, pubKeySz);
@@ -1741,11 +1743,12 @@ static INLINE int myEccSharedSecret(WOLFSSL* ssl, ecc_key* otherKey,
else if (side == WOLFSSL_SERVER_END) { else if (side == WOLFSSL_SERVER_END) {
privKey = otherKey; privKey = otherKey;
pubKey = &tmpKey; pubKey = &tmpKey;
ret = wc_ecc_import_x963_ex(pubKeyDer, *pubKeySz, pubKey, ret = wc_ecc_import_x963_ex(pubKeyDer, *pubKeySz, pubKey,
otherKey->dp->id); otherKey->dp->id);
} }
else { else {
ret = -1; ret = BAD_FUNC_ARG;
} }
/* generate shared secret and return it */ /* generate shared secret and return it */