summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2022-11-08 16:48:28 +0000
committertb <>2022-11-08 16:48:28 +0000
commit910832787fcc42c244eb0954d09b6acedd98f7c8 (patch)
treea6a922d94f86be7e0c7d9c456a360dc99c28b226 /src/lib
parent9df2d7b7275fffbc1aa88950a41601caeafc6a41 (diff)
downloadopenbsd-910832787fcc42c244eb0954d09b6acedd98f7c8.tar.gz
openbsd-910832787fcc42c244eb0954d09b6acedd98f7c8.tar.bz2
openbsd-910832787fcc42c244eb0954d09b6acedd98f7c8.zip
Avoid signed integer overflow in i2c_ASN1_BIT_STRING()
If the length of the bitstring is INT_MAX, adding 1 to it is undefined behavior, so error out before doing so. Based on BoringSSL eeb3333f by davidben ok beck joshua
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index c30b8f5b65..a4a379a9a0 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.36 2022/05/17 09:17:20 tb Exp $ */ 1/* $OpenBSD: a_bitstr.c,v 1.37 2022/11/08 16:48:28 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 *
@@ -241,6 +241,14 @@ i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
241 if (a == NULL) 241 if (a == NULL)
242 return (0); 242 return (0);
243 243
244 if (a->length == INT_MAX)
245 return (0);
246
247 ret = a->length + 1;
248
249 if (pp == NULL)
250 return (ret);
251
244 len = a->length; 252 len = a->length;
245 253
246 if (len > 0) { 254 if (len > 0) {
@@ -274,10 +282,6 @@ i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
274 } else 282 } else
275 bits = 0; 283 bits = 0;
276 284
277 ret = 1 + len;
278 if (pp == NULL)
279 return (ret);
280
281 p= *pp; 285 p= *pp;
282 286
283 *(p++) = (unsigned char)bits; 287 *(p++) = (unsigned char)bits;