Skip to content

Fix potential vulnerable cloned function #8572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extern/libtommath/bn_fast_s_mp_mul_digs.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
mp_digit W[MP_WARRAY];
register mp_word _W;

if (digs < 0) {
return MP_VAL;
}

/* grow the destination as required */
if (c->alloc < digs) {
if ((res = mp_grow (c, digs)) != MP_OKAY) {
Expand Down
4 changes: 4 additions & 0 deletions extern/libtommath/bn_fast_s_mp_mul_high_digs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
mp_digit W[MP_WARRAY];
mp_word _W;

if (digs < 0) {
return MP_VAL;
}

/* grow the destination as required */
pa = a->used + b->used;
if (c->alloc < pa) {
Expand Down
4 changes: 4 additions & 0 deletions extern/libtommath/bn_mp_2expt.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ mp_2expt (mp_int * a, int b)
{
int res;

if (b < 0) {
return MP_VAL;
}

/* zero a as per default */
mp_zero (a);

Expand Down
4 changes: 4 additions & 0 deletions extern/libtommath/bn_mp_grow.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ int mp_grow (mp_int * a, int size)
int i;
mp_digit *tmp;

if (size < 0) {
return MP_VAL;
}

/* if the alloc size is smaller alloc more ram */
if (a->alloc < size) {
/* ensure there are always at least MP_PREC digits extra on top */
Expand Down
4 changes: 4 additions & 0 deletions extern/libtommath/bn_mp_init_size.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ int mp_init_size (mp_int * a, int size)
{
int x;

if (size < 0) {
return MP_VAL;
}

/* pad size so there are always extra digits */
size += (MP_PREC * 2) - (size % MP_PREC);

Expand Down
4 changes: 4 additions & 0 deletions extern/libtommath/bn_mp_mul_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ int mp_mul_2d (mp_int * a, int b, mp_int * c)
mp_digit d;
int res;

if (b < 0) {
return MP_VAL;
}

/* copy */
if (a != c) {
if ((res = mp_copy (a, c)) != MP_OKAY) {
Expand Down
4 changes: 4 additions & 0 deletions extern/libtommath/bn_s_mp_mul_digs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
mp_word r;
mp_digit tmpx, *tmpt, *tmpy;

if (digs < 0) {
return MP_VAL;
}

/* can we use the fast multiplier? */
if (((digs) < MP_WARRAY) &&
MIN (a->used, b->used) <
Expand Down
4 changes: 4 additions & 0 deletions extern/libtommath/bn_s_mp_mul_high_digs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
mp_word r;
mp_digit tmpx, *tmpt, *tmpy;

if (digs < 0) {
return MP_VAL;
}

/* can we use the fast multiplier? */
#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
if (((a->used + b->used + 1) < MP_WARRAY)
Expand Down
Loading