Fix possible use of ForceZero with NULL pointer. Improve init of "kb" when small stack disabled, so memset isn't performed twice.

This commit is contained in:
David Garske
2016-06-22 07:22:30 -07:00
parent 69db94d668
commit 47c1f4e68f

View File

@@ -4326,7 +4326,7 @@ static int accel_fp_mul2add(int idx1, int idx2,
#define KB_SIZE 128
#ifdef WOLFSSL_SMALL_STACK
unsigned char* kb[2];
unsigned char* kb[2] = {NULL, NULL};
#else
unsigned char kb[2][KB_SIZE];
#endif
@@ -4337,8 +4337,6 @@ static int accel_fp_mul2add(int idx1, int idx2,
if (mp_init_multi(&tka, &tkb, &order, NULL, NULL, NULL) != MP_OKAY)
return MP_INIT_E;
XMEMSET(kb, 0, sizeof(kb));
/* if it's smaller than modulus we fine */
if (mp_unsigned_bin_size(kA) > mp_unsigned_bin_size(modulus)) {
/* find order */
@@ -4526,8 +4524,10 @@ done:
mp_clear(&order);
#endif
ForceZero(kb[0], KB_SIZE);
ForceZero(kb[1], KB_SIZE);
if (kb[0])
ForceZero(kb[0], KB_SIZE);
if (kb[1])
ForceZero(kb[1], KB_SIZE);
#ifdef WOLFSSL_SMALL_STACK
XFREE(kb[0], NULL, DYNAMIC_TYPE_TMP_BUFFER);