]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix a buffer overflow in drbg_ctr_generate
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Tue, 2 Jun 2020 09:52:24 +0000 (11:52 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Wed, 3 Jun 2020 11:15:36 +0000 (13:15 +0200)
This can happen if the 32-bit counter overflows
and the last block is not a multiple of 16 bytes.

Fixes #12012

[extended tests]

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/12016)

crypto/rand/drbg_ctr.c

index 050ae496526e8d0b887463a4735479b2f1836835..33e1b324c6a5758ac694dc0d6043e28718bdff71 100644 (file)
@@ -366,9 +366,11 @@ __owur static int drbg_ctr_generate(RAND_DRBG *drbg,
         ctr32 = GETU32(ctr->V + 12) + blocks;
         if (ctr32 < blocks) {
             /* 32-bit counter overflow into V. */
-            blocks -= ctr32;
-            buflen = blocks * 16;
-            ctr32 = 0;
+            if (ctr32 != 0) {
+                blocks -= ctr32;
+                buflen = blocks * 16;
+                ctr32 = 0;
+            }
             ctr96_inc(ctr->V);
         }
         PUTU32(ctr->V + 12, ctr32);