Bug 1372244 - Check for OOM after malloc() in mp_exptmod_f() r=franziskus
authorTim Taubert <ttaubert@mozilla.com>
Mon, 12 Jun 2017 17:12:26 +0200
changeset 13439 70ff6d097ae9
parent 13438 8cd50ae99b50
child 13440 ea7b2fad9fc2
push id2252
push userttaubert@mozilla.com
push date2017-06-12 15:14 +0000
reviewersfranziskus
bugs1372244
Bug 1372244 - Check for OOM after malloc() in mp_exptmod_f() r=franziskus Differential Revision: https://nss-review.dev.mozaws.net/D352
lib/freebl/mpi/mpmontg.c
--- a/lib/freebl/mpi/mpmontg.c
+++ b/lib/freebl/mpi/mpmontg.c
@@ -200,17 +200,21 @@ mp_exptmod_f(const mp_int *montBase,
     mp_set(&accum1, 1);
     MP_CHECKOK(s_mp_to_mont(&accum1, mmm, &accum1));
     MP_CHECKOK(s_mp_pad(&accum1, nLen));
 
     oddPowSize = 2 * nLen + 1;
     dTmpSize = 2 * oddPowSize;
     dSize = sizeof(double) * (nLen * 4 + 1 +
                               ((odd_ints + 1) * oddPowSize) + dTmpSize);
-    dBuf = (double *)malloc(dSize);
+    dBuf = malloc(dSize);
+    if (!dBuf) {
+        res = MP_MEM;
+        goto CLEANUP;
+    }
     dm1 = dBuf;           /* array of d32 */
     dn = dBuf + nLen;     /* array of d32 */
     dSqr = dn + nLen;     /* array of d32 */
     d16Tmp = dSqr + nLen; /* array of d16 */
     dTmp = d16Tmp + oddPowSize;
 
     for (i = 0; i < odd_ints; ++i) {
         oddPowers[i] = dTmp;