]> 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>
Sat, 20 Feb 2021 12:41:59 +0000 (15:41 +0300)
gost_keyexpimp.c

index b9602002f617c69e2fd5a4f6b87590d25aaa66f2..e4af4180944cae514cbe334b6b99d85d04c7cea7 100644 (file)
@@ -46,6 +46,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);
@@ -123,6 +128,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);