Skip to content

Commit be78ab9

Browse files
czurniedensjaeckel
authored andcommitted
Fix possible integer overflow
(cherry picked from commit beba892)
1 parent 7f96509 commit be78ab9

7 files changed

+28
-0
lines changed

mp_2expt.c

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ mp_err mp_2expt(mp_int *a, int b)
1212
{
1313
mp_err err;
1414

15+
if (b < 0) {
16+
return MP_VAL;
17+
}
18+
1519
/* zero a as per default */
1620
mp_zero(a);
1721

mp_grow.c

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
/* grow as required */
77
mp_err mp_grow(mp_int *a, int size)
88
{
9+
if (size < 0) {
10+
return MP_VAL;
11+
}
12+
913
/* if the alloc size is smaller alloc more ram */
1014
if (a->alloc < size) {
1115
mp_digit *dp;

mp_init_size.c

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
/* init an mp_init for a given size */
77
mp_err mp_init_size(mp_int *a, int size)
88
{
9+
if (size < 0) {
10+
return MP_VAL;
11+
}
12+
913
size = MP_MAX(MP_MIN_DIGIT_COUNT, size);
1014

1115
if (size > MP_MAX_DIGIT_COUNT) {

s_mp_mul.c

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ mp_err s_mp_mul(const mp_int *a, const mp_int *b, mp_int *c, int digs)
1313
mp_err err;
1414
int pa, ix;
1515

16+
if (digs < 0) {
17+
return MP_VAL;
18+
}
19+
1620
/* can we use the fast multiplier? */
1721
if ((digs < MP_WARRAY) &&
1822
(MP_MIN(a->used, b->used) < MP_MAX_COMBA)) {

s_mp_mul_comba.c

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ mp_err s_mp_mul_comba(const mp_int *a, const mp_int *b, mp_int *c, int digs)
2626
mp_digit W[MP_WARRAY];
2727
mp_word _W;
2828

29+
if (digs < 0) {
30+
return MP_VAL;
31+
}
32+
2933
/* grow the destination as required */
3034
if ((err = mp_grow(c, digs)) != MP_OKAY) {
3135
return err;

s_mp_mul_high.c

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ mp_err s_mp_mul_high(const mp_int *a, const mp_int *b, mp_int *c, int digs)
1212
int pa, pb, ix;
1313
mp_err err;
1414

15+
if (digs < 0) {
16+
return MP_VAL;
17+
}
18+
1519
/* can we use the fast multiplier? */
1620
if (MP_HAS(S_MP_MUL_HIGH_COMBA)
1721
&& ((a->used + b->used + 1) < MP_WARRAY)

s_mp_mul_high_comba.c

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ mp_err s_mp_mul_high_comba(const mp_int *a, const mp_int *b, mp_int *c, int digs
1919
mp_digit W[MP_WARRAY];
2020
mp_word _W;
2121

22+
if (digs < 0) {
23+
return MP_VAL;
24+
}
25+
2226
/* grow the destination as required */
2327
pa = a->used + b->used;
2428
if ((err = mp_grow(c, pa)) != MP_OKAY) {

0 commit comments

Comments
 (0)