summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-01-13 14:46:08 +0000
committertb <>2023-01-13 14:46:08 +0000
commitf80a4029bb2f43fe5f0270857d48bc9d41d3ea4e (patch)
tree7e39f565ad41530ea5ed02d36032be18c204e2de /src/lib
parent8fd11b09ad30a3305ae1c73fe6455f609f882196 (diff)
downloadopenbsd-f80a4029bb2f43fe5f0270857d48bc9d41d3ea4e.tar.gz
openbsd-f80a4029bb2f43fe5f0270857d48bc9d41d3ea4e.tar.bz2
openbsd-f80a4029bb2f43fe5f0270857d48bc9d41d3ea4e.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/lib')
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c6
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)