diff options
| author | tb <> | 2023-01-13 14:46:08 +0000 |
|---|---|---|
| committer | tb <> | 2023-01-13 14:46:08 +0000 |
| commit | 38ed78ca28e1e252895ca064c8388657440e5142 (patch) | |
| tree | 7e39f565ad41530ea5ed02d36032be18c204e2de /src | |
| parent | 6ba01df7843c208cabc369d1ab8c75b71d3df26d (diff) | |
| download | openbsd-38ed78ca28e1e252895ca064c8388657440e5142.tar.gz openbsd-38ed78ca28e1e252895ca064c8388657440e5142.tar.bz2 openbsd-38ed78ca28e1e252895ca064c8388657440e5142.zip | |
Prevent 1-byte out-of-bounds read in i2c_ASN1_BIT_STRING
If an ASN.1 BIT STRING a of length > 0 contains only zero bytes in a->data,
this old code would end up reading from a->data[-1]. This may or may not
crash. Luckily, anton observed two openssl-ruby regress test failures in
the last few days, which could eventually be traced back to this (after a
lot of painful digging due to coredumps not working properly).
ok jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_bitstr.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c index a4a379a9a0..767055144d 100644 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ b/src/lib/libcrypto/asn1/a_bitstr.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: a_bitstr.c,v 1.37 2022/11/08 16:48:28 tb Exp $ */ | 1 | /* $OpenBSD: a_bitstr.c,v 1.38 2023/01/13 14:46:08 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 | * |
| @@ -255,11 +255,13 @@ i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) | |||
| 255 | if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) { | 255 | if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) { |
| 256 | bits = (int)a->flags & 0x07; | 256 | bits = (int)a->flags & 0x07; |
| 257 | } else { | 257 | } else { |
| 258 | j = 0; | ||
| 258 | for (; len > 0; len--) { | 259 | for (; len > 0; len--) { |
| 259 | if (a->data[len - 1]) | 260 | if (a->data[len - 1]) |
| 260 | break; | 261 | break; |
| 261 | } | 262 | } |
| 262 | j = a->data[len - 1]; | 263 | if (len > 0) |
| 264 | j = a->data[len - 1]; | ||
| 263 | if (j & 0x01) | 265 | if (j & 0x01) |
| 264 | bits = 0; | 266 | bits = 0; |
| 265 | else if (j & 0x02) | 267 | else if (j & 0x02) |
