diff options
| author | tb <> | 2022-06-22 09:03:06 +0000 |
|---|---|---|
| committer | tb <> | 2022-06-22 09:03:06 +0000 |
| commit | c14c866133ab158b515b98c08cc377637fc8bb7e (patch) | |
| tree | 1d72c28f53847258f82bcb34944799c9d1d4443a /src | |
| parent | 0c232807de21f389f04ef3f8c2f3fb8d2e093e8c (diff) | |
| download | openbsd-c14c866133ab158b515b98c08cc377637fc8bb7e.tar.gz openbsd-c14c866133ab158b515b98c08cc377637fc8bb7e.tar.bz2 openbsd-c14c866133ab158b515b98c08cc377637fc8bb7e.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 | ||
