From 03f9cafa4b84662d79e5e4df63b4bba3d2c296ac Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 27 Dec 2012 11:18:29 -0800 Subject: [PATCH] ecc_verify_hash was leaking two mp_ints --- ctaocrypt/src/ecc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ctaocrypt/src/ecc.c b/ctaocrypt/src/ecc.c index 1976b3d12..ef35477f2 100644 --- a/ctaocrypt/src/ecc.c +++ b/ctaocrypt/src/ecc.c @@ -1266,17 +1266,17 @@ int ecc_verify_hash(const byte* sig, word32 siglen, byte* hash, word32 hashlen, } /* allocate ints */ - if ((err = mp_init_multi(&r, &s, &v, &w, &u1, &u2)) != MP_OKAY) { + if ((err = mp_init_multi(&v, &w, &u1, &u2, &p, &e)) != MP_OKAY) { return MEMORY_E; } - if ((err = mp_init_multi(&p, &e, &m, NULL, NULL, NULL)) != MP_OKAY) { - mp_clear(&r); - mp_clear(&s); + if ((err = mp_init(&m)) != MP_OKAY) { mp_clear(&v); mp_clear(&w); mp_clear(&u1); mp_clear(&u2); + mp_clear(&p); + mp_clear(&e); return MEMORY_E; } @@ -1286,6 +1286,12 @@ int ecc_verify_hash(const byte* sig, word32 siglen, byte* hash, word32 hashlen, if (mQ == NULL || mG == NULL) err = MEMORY_E; + /* Note, DecodeECC_DSA_Sig() calls mp_init() on r and s. + * If either of those don't allocate correctly, none of + * the rest of this function will execute, and everything + * gets cleaned up at the end. */ + XMEMSET(&r, 0, sizeof(r)); + XMEMSET(&s, 0, sizeof(s)); if (err == MP_OKAY) err = DecodeECC_DSA_Sig(sig, siglen, &r, &s);