From f77458992e1c766a574cee19dc7e8c1274dcad0d Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Tue, 28 Feb 2017 14:33:07 -0700 Subject: [PATCH] resolve windows warnings and add sanity check with PKCS12 parse --- wolfcrypt/src/ecc.c | 3 ++- wolfcrypt/src/hmac.c | 12 ++++-------- wolfcrypt/src/integer.c | 4 ++++ wolfcrypt/src/pkcs12.c | 4 ++++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 019b96366..ac813d280 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -7070,7 +7070,8 @@ int do_mp_jacobi(mp_int* a, mp_int* n, int* c); int do_mp_jacobi(mp_int* a, mp_int* n, int* c) { - int k, s, r, res; + int k, s, res; + int r = 0; /* initialize to help static analysis out */ mp_digit residue; /* if a < 0 return MP_VAL */ diff --git a/wolfcrypt/src/hmac.c b/wolfcrypt/src/hmac.c index c8785883d..271ccd43b 100644 --- a/wolfcrypt/src/hmac.c +++ b/wolfcrypt/src/hmac.c @@ -830,15 +830,11 @@ int wc_HKDF(int type, const byte* inKey, word32 inKeySz, saltSz = hashSz; } - do { ret = wc_HmacSetKey(&myHmac, type, localSalt, saltSz); - if (ret != 0) - break; - ret = wc_HmacUpdate(&myHmac, inKey, inKeySz); - if (ret != 0) - break; - ret = wc_HmacFinal(&myHmac, prk); - } while (0); + if (ret == 0) + ret = wc_HmacUpdate(&myHmac, inKey, inKeySz); + if (ret == 0) + ret = wc_HmacFinal(&myHmac, prk); if (ret == 0) { while (outIdx < outSz) { diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index efa0af912..9c45c7602 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -4223,6 +4223,10 @@ static int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d) q.used = a->used; q.sign = a->sign; } + else { + mp_init(&q); /* initialize to help static analysis */ + } + w = 0; for (ix = a->used - 1; ix >= 0; ix--) { diff --git a/wolfcrypt/src/pkcs12.c b/wolfcrypt/src/pkcs12.c index edcc634d5..24877b60d 100644 --- a/wolfcrypt/src/pkcs12.c +++ b/wolfcrypt/src/pkcs12.c @@ -709,6 +709,10 @@ int wc_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw, } } + if (pkcs12->safe == NULL) { + WOLFSSL_MSG("No PKCS12 safes to parse"); + return BAD_FUNC_ARG; + } /* Decode content infos */ ci = pkcs12->safe->CI;