Merge pull request #792 from SparkiDev/valgrind

Fix valgrind issues
This commit is contained in:
toddouska
2017-03-14 13:50:26 -07:00
committed by GitHub
2 changed files with 35 additions and 2 deletions

View File

@ -2220,8 +2220,10 @@ int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
} }
#endif /* OPENSSL_EXTRA */ #endif /* OPENSSL_EXTRA */
if (GetInt(&key->n, input, inOutIdx, inSz) < 0 || if (GetInt(&key->n, input, inOutIdx, inSz) < 0)
GetInt(&key->e, input, inOutIdx, inSz) < 0) { return ASN_RSA_KEY_E;
if (GetInt(&key->e, input, inOutIdx, inSz) < 0) {
mp_clear(&key->n);
return ASN_RSA_KEY_E; return ASN_RSA_KEY_E;
} }

View File

@ -5869,11 +5869,19 @@ static int rsa_decode_test(void)
ret = -525; ret = -525;
goto done; goto done;
} }
wc_FreeRsaKey(&keyPub);
ret = wc_InitRsaKey(&keyPub, NULL);
if (ret != 0)
return -520;
ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, -1, &keyPub); ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, -1, &keyPub);
if (ret != 0) { if (ret != 0) {
ret = -526; ret = -526;
goto done; goto done;
} }
wc_FreeRsaKey(&keyPub);
ret = wc_InitRsaKey(&keyPub, NULL);
if (ret != 0)
return -520;
/* Use API. */ /* Use API. */
ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), &keyPub); ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), &keyPub);
@ -5881,6 +5889,10 @@ static int rsa_decode_test(void)
ret = -527; ret = -527;
goto done; goto done;
} }
wc_FreeRsaKey(&keyPub);
ret = wc_InitRsaKey(&keyPub, NULL);
if (ret != 0)
return -520;
/* Parameter Validation testing. */ /* Parameter Validation testing. */
inSz = sizeof(good); inSz = sizeof(good);
@ -5974,6 +5986,10 @@ static int rsa_decode_test(void)
goto done; goto done;
} }
/* TODO: Shouldn't ignore object id's data. */ /* TODO: Shouldn't ignore object id's data. */
wc_FreeRsaKey(&keyPub);
ret = wc_InitRsaKey(&keyPub, NULL);
if (ret != 0)
return -520;
/* Valid data cases. */ /* Valid data cases. */
inSz = sizeof(good); inSz = sizeof(good);
@ -5987,6 +6003,10 @@ static int rsa_decode_test(void)
ret = -551; ret = -551;
goto done; goto done;
} }
wc_FreeRsaKey(&keyPub);
ret = wc_InitRsaKey(&keyPub, NULL);
if (ret != 0)
return -520;
inSz = sizeof(goodAlgId); inSz = sizeof(goodAlgId);
inOutIdx = 0; inOutIdx = 0;
@ -5999,6 +6019,10 @@ static int rsa_decode_test(void)
ret = -553; ret = -553;
goto done; goto done;
} }
wc_FreeRsaKey(&keyPub);
ret = wc_InitRsaKey(&keyPub, NULL);
if (ret != 0)
return -520;
inSz = sizeof(goodAlgIdNull); inSz = sizeof(goodAlgIdNull);
inOutIdx = 0; inOutIdx = 0;
@ -6011,6 +6035,10 @@ static int rsa_decode_test(void)
ret = -555; ret = -555;
goto done; goto done;
} }
wc_FreeRsaKey(&keyPub);
ret = wc_InitRsaKey(&keyPub, NULL);
if (ret != 0)
return -520;
inSz = sizeof(goodBitStrNoZero); inSz = sizeof(goodBitStrNoZero);
inOutIdx = 0; inOutIdx = 0;
@ -10260,6 +10288,9 @@ static int ecc_exp_imp_test(ecc_key* key)
goto done; goto done;
} }
wc_ecc_free(&keyImp);
wc_ecc_init(&keyImp);
ret = wc_ecc_import_raw_ex(&keyImp, qx, qy, d, ECC_SECP256R1); ret = wc_ecc_import_raw_ex(&keyImp, qx, qy, d, ECC_SECP256R1);
if (ret != 0) { if (ret != 0) {
ret = -1073; ret = -1073;