diff options
author | tb <> | 2022-06-22 09:03:06 +0000 |
---|---|---|
committer | tb <> | 2022-06-22 09:03:06 +0000 |
commit | 06fb2fa6691b3cf46976d202bddc49acd66539a7 (patch) | |
tree | 1d72c28f53847258f82bcb34944799c9d1d4443a /src | |
parent | 8d061b8c94a7612312555460a005d275b38e3ae4 (diff) | |
download | openbsd-06fb2fa6691b3cf46976d202bddc49acd66539a7.tar.gz openbsd-06fb2fa6691b3cf46976d202bddc49acd66539a7.tar.bz2 openbsd-06fb2fa6691b3cf46976d202bddc49acd66539a7.zip |
Error out on negative shifts in BN_{r,l}shift()
Without these checks in both functions nw = n / BN_BITS2 will be negative
and this leads to out-of-bounds accesses via negative array indices and
memset with a negative size.
Pointed out by cheloha
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_shift.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c index 0e8211e3d6..e89e157446 100644 --- a/src/lib/libcrypto/bn/bn_shift.c +++ b/src/lib/libcrypto/bn/bn_shift.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_shift.c,v 1.13 2014/10/28 07:35:58 jsg Exp $ */ | 1 | /* $OpenBSD: bn_shift.c,v 1.14 2022/06/22 09:03:06 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 | * |
@@ -59,6 +59,8 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <string.h> | 60 | #include <string.h> |
61 | 61 | ||
62 | #include <openssl/err.h> | ||
63 | |||
62 | #include "bn_lcl.h" | 64 | #include "bn_lcl.h" |
63 | 65 | ||
64 | int | 66 | int |
@@ -138,6 +140,11 @@ BN_lshift(BIGNUM *r, const BIGNUM *a, int n) | |||
138 | BN_ULONG *t, *f; | 140 | BN_ULONG *t, *f; |
139 | BN_ULONG l; | 141 | BN_ULONG l; |
140 | 142 | ||
143 | if (n < 0) { | ||
144 | BNerror(BN_R_INVALID_LENGTH); | ||
145 | return 0; | ||
146 | } | ||
147 | |||
141 | bn_check_top(r); | 148 | bn_check_top(r); |
142 | bn_check_top(a); | 149 | bn_check_top(a); |
143 | 150 | ||
@@ -175,6 +182,11 @@ BN_rshift(BIGNUM *r, const BIGNUM *a, int n) | |||
175 | BN_ULONG *t, *f; | 182 | BN_ULONG *t, *f; |
176 | BN_ULONG l, tmp; | 183 | BN_ULONG l, tmp; |
177 | 184 | ||
185 | if (n < 0) { | ||
186 | BNerror(BN_R_INVALID_LENGTH); | ||
187 | return 0; | ||
188 | } | ||
189 | |||
178 | bn_check_top(r); | 190 | bn_check_top(r); |
179 | bn_check_top(a); | 191 | bn_check_top(a); |
180 | 192 | ||