wolfcrypt/src/sp_int.c: clear whole struct in sp_init() and sp_init_multi(), to fix uninited pointer free()s in sp_free() when --enable-sp-math -DHAVE_WOLF_BIGINT.

This commit is contained in:
Daniel Pouzzner
2020-08-26 00:35:02 -05:00
parent 9b7c753165
commit c5d28c16b5

View File

@ -102,7 +102,7 @@ int sp_get_digit_count(sp_int *a)
*/ */
int sp_init(sp_int* a) int sp_init(sp_int* a)
{ {
a->used = 0; XMEMSET(a,0,sizeof *a);
a->size = SP_INT_DIGITS; a->size = SP_INT_DIGITS;
#ifdef HAVE_WOLF_BIGINT #ifdef HAVE_WOLF_BIGINT
wc_bigint_init(&a->raw); wc_bigint_init(&a->raw);
@ -125,42 +125,42 @@ int sp_init_multi(sp_int* a, sp_int* b, sp_int* c, sp_int* d, sp_int* e,
sp_int* f) sp_int* f)
{ {
if (a != NULL) { if (a != NULL) {
a->used = 0; XMEMSET(a,0,sizeof *a);
a->size = SP_INT_DIGITS; a->size = SP_INT_DIGITS;
#ifdef HAVE_WOLF_BIGINT #ifdef HAVE_WOLF_BIGINT
wc_bigint_init(&a->raw); wc_bigint_init(&a->raw);
#endif #endif
} }
if (b != NULL) { if (b != NULL) {
b->used = 0; XMEMSET(b,0,sizeof *b);
b->size = SP_INT_DIGITS; b->size = SP_INT_DIGITS;
#ifdef HAVE_WOLF_BIGINT #ifdef HAVE_WOLF_BIGINT
wc_bigint_init(&b->raw); wc_bigint_init(&b->raw);
#endif #endif
} }
if (c != NULL) { if (c != NULL) {
c->used = 0; XMEMSET(c,0,sizeof *c);
c->size = SP_INT_DIGITS; c->size = SP_INT_DIGITS;
#ifdef HAVE_WOLF_BIGINT #ifdef HAVE_WOLF_BIGINT
wc_bigint_init(&c->raw); wc_bigint_init(&c->raw);
#endif #endif
} }
if (d != NULL) { if (d != NULL) {
d->used = 0; XMEMSET(d,0,sizeof *d);
d->size = SP_INT_DIGITS; d->size = SP_INT_DIGITS;
#ifdef HAVE_WOLF_BIGINT #ifdef HAVE_WOLF_BIGINT
wc_bigint_init(&d->raw); wc_bigint_init(&d->raw);
#endif #endif
} }
if (e != NULL) { if (e != NULL) {
e->used = 0; XMEMSET(e,0,sizeof *e);
e->size = SP_INT_DIGITS; e->size = SP_INT_DIGITS;
#ifdef HAVE_WOLF_BIGINT #ifdef HAVE_WOLF_BIGINT
wc_bigint_init(&e->raw); wc_bigint_init(&e->raw);
#endif #endif
} }
if (f != NULL) { if (f != NULL) {
f->used = 0; XMEMSET(f,0,sizeof *f);
f->size = SP_INT_DIGITS; f->size = SP_INT_DIGITS;
#ifdef HAVE_WOLF_BIGINT #ifdef HAVE_WOLF_BIGINT
wc_bigint_init(&f->raw); wc_bigint_init(&f->raw);