]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Avoid some buffer overflows
authorDmitry Belyavskiy <beldmit@gmail.com>
Sat, 20 Feb 2021 12:41:59 +0000 (15:41 +0300)
committerDmitry Belyavskiy <beldmit@gmail.com>
Fri, 26 Feb 2021 09:26:21 +0000 (10:26 +0100)
gost_keyexpimp.c

index b94531f0e23e1ea2abc07dcadc612475785ddbc1..7c28a03029011c946c1c15324de9063305a397ba 100644 (file)
@@ -39,6 +39,11 @@ int gost_kexp15(const unsigned char *shared_key, const int shared_len,
         goto err;
     }
 
+    if (shared_len + mac_len > (unsigned int)(*out_len)) {
+        GOSTerr(GOST_F_GOST_KEXP15, ERR_R_INTERNAL_ERROR);
+        goto err;
+    }
+
     /* we expect IV of half length */
     memset(iv_full, 0, 16);
     memcpy(iv_full, iv, ivlen);
@@ -116,6 +121,16 @@ int gost_kimp15(const unsigned char *expkey, const size_t expkeylen,
         goto err;
     }
 
+    if (expkeylen > sizeof(out)) {
+        GOSTerr(GOST_F_GOST_KIMP15, ERR_R_INTERNAL_ERROR);
+        goto err;
+    }
+
+    if (ivlen > 16) {
+        GOSTerr(GOST_F_GOST_KIMP15, ERR_R_INTERNAL_ERROR);
+        goto err;
+    }
+
     /* we expect IV of half length */
     memset(iv_full, 0, 16);
     memcpy(iv_full, iv, ivlen);