summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2020-09-12 15:24:39 +0000
committertb <>2020-09-12 15:24:39 +0000
commit724fa19847a977c5790a4e1d0b2e4fe6d95646fa (patch)
tree5a549ecb20fabf7acfb6c6d959ea80a0dd05abd8 /src/lib
parentd7dfc10134411f17602aa3f2d5224ccb44f6701c (diff)
downloadopenbsd-724fa19847a977c5790a4e1d0b2e4fe6d95646fa.tar.gz
openbsd-724fa19847a977c5790a4e1d0b2e4fe6d95646fa.tar.bz2
openbsd-724fa19847a977c5790a4e1d0b2e4fe6d95646fa.zip
Avoid an out-of-bounds access in BN_rand()
If BN_rand() is called with top > 0 and bits == 1, it would allocate a buf[] of size 1 and set the top bit of buf[1]. Found in OpenSSL commit efee575ad464bfb60bf72dcb73f9b51768f4b1a1 while looking for something else. ok beck djm inoguchi
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
index df798f41bc..4626960a0d 100644
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_rand.c,v 1.22 2018/11/06 06:49:45 tb Exp $ */ 1/* $OpenBSD: bn_rand.c,v 1.23 2020/09/12 15:24:39 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -129,6 +129,11 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
129 return (0); 129 return (0);
130 } 130 }
131 131
132 if (bits < 0 || (bits == 1 && top > 0)) {
133 BNerror(BN_R_BITS_TOO_SMALL);
134 return (0);
135 }
136
132 if (bits == 0) { 137 if (bits == 0) {
133 BN_zero(rnd); 138 BN_zero(rnd);
134 return (1); 139 return (1);
@@ -166,8 +171,8 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
166 } 171 }
167#endif 172#endif
168 173
169 if (top != -1) { 174 if (top >= 0) {
170 if (top) { 175 if (top > 0) {
171 if (bit == 0) { 176 if (bit == 0) {
172 buf[0] = 1; 177 buf[0] = 1;
173 buf[1] |= 0x80; 178 buf[1] |= 0x80;