Don't cast the potential problems away, handle them appropriately
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
diff --git a/bn_mp_div.c b/bn_mp_div.c
index 3dc28c9..630f2dc 100644
--- a/bn_mp_div.c
+++ b/bn_mp_div.c
@@ -270,7 +270,9 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
}
if (d != NULL) {
- (void)mp_div_2d (&x, norm, &x, NULL);
+ if ((res = mp_div_2d (&x, norm, &x, NULL)) != MP_OKAY) {
+ goto LBL_Y;
+ }
mp_exch (&x, d);
}
diff --git a/bn_mp_dr_reduce.c b/bn_mp_dr_reduce.c
index 62e9612..7cfe462 100644
--- a/bn_mp_dr_reduce.c
+++ b/bn_mp_dr_reduce.c
@@ -82,7 +82,9 @@ top:
* Each successive "recursion" makes the input smaller and smaller.
*/
if (mp_cmp_mag (x, n) != MP_LT) {
- (void)s_mp_sub(x, n, x);
+ if ((err = s_mp_sub(x, n, x)) != MP_OKAY) {
+ return err;
+ }
goto top;
}
return MP_OKAY;
diff --git a/bn_mp_exteuclid.c b/bn_mp_exteuclid.c
index 3b0bb4a..624f81d 100644
--- a/bn_mp_exteuclid.c
+++ b/bn_mp_exteuclid.c
@@ -61,9 +61,9 @@ int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
/* make sure U3 >= 0 */
if (u3.sign == MP_NEG) {
- (void)mp_neg(&u1, &u1);
- (void)mp_neg(&u2, &u2);
- (void)mp_neg(&u3, &u3);
+ if ((err = mp_neg(&u1, &u1)) != MP_OKAY) { goto _ERR; }
+ if ((err = mp_neg(&u2, &u2)) != MP_OKAY) { goto _ERR; }
+ if ((err = mp_neg(&u3, &u3)) != MP_OKAY) { goto _ERR; }
}
/* copy result out */
diff --git a/bn_mp_reduce_2k.c b/bn_mp_reduce_2k.c
index f03bc11..6abae6c 100644
--- a/bn_mp_reduce_2k.c
+++ b/bn_mp_reduce_2k.c
@@ -45,7 +45,9 @@ top:
}
if (mp_cmp_mag(a, n) != MP_LT) {
- (void)s_mp_sub(a, n, a);
+ if ((res = s_mp_sub(a, n, a)) != MP_OKAY) {
+ goto ERR;
+ }
goto top;
}
diff --git a/bn_mp_reduce_2k_l.c b/bn_mp_reduce_2k_l.c
index 0ee5402..84198a3 100644
--- a/bn_mp_reduce_2k_l.c
+++ b/bn_mp_reduce_2k_l.c
@@ -46,7 +46,9 @@ top:
}
if (mp_cmp_mag(a, n) != MP_LT) {
- (void)s_mp_sub(a, n, a);
+ if ((res = s_mp_sub(a, n, a)) != MP_OKAY) {
+ goto ERR;
+ }
goto top;
}
diff --git a/bn_mp_toom_mul.c b/bn_mp_toom_mul.c
index 81fec9f..e2a4ac8 100644
--- a/bn_mp_toom_mul.c
+++ b/bn_mp_toom_mul.c
@@ -46,7 +46,9 @@ int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
goto ERR;
}
mp_rshd(&a1, B);
- (void)mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
+ if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
+ goto ERR;
+ }
if ((res = mp_copy(a, &a2)) != MP_OKAY) {
goto ERR;
diff --git a/bn_mp_toom_sqr.c b/bn_mp_toom_sqr.c
index d2c096c..0fe967b 100644
--- a/bn_mp_toom_sqr.c
+++ b/bn_mp_toom_sqr.c
@@ -39,7 +39,9 @@ mp_toom_sqr(mp_int *a, mp_int *b)
goto ERR;
}
mp_rshd(&a1, B);
- (void)mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
+ if ((res = mp_mod_2d(&a1, DIGIT_BIT * B, &a1)) != MP_OKAY) {
+ goto ERR;
+ }
if ((res = mp_copy(a, &a2)) != MP_OKAY) {
goto ERR;