summaryrefslogtreecommitdiff
path: root/lib/libcrypto
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2019-04-28 05:05:57 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2019-04-28 05:05:57 +0000
commitb9f62336b9c984602af38f6e737f034805bb437d (patch)
treeb977933b6c2bced80b3dda09357c34ac57f44dcc /lib/libcrypto
parent4093135d10ec61004327eb10ba70e94a68194946 (diff)
Avoid an undefined shift in ASN1_ENUMERATED_get().
(same fix as in a_int.c rev 1.34) Fixes oss-fuzz issue #13809 ok beck, jsing
Diffstat (limited to 'lib/libcrypto')
-rw-r--r--lib/libcrypto/asn1/a_enum.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/libcrypto/asn1/a_enum.c b/lib/libcrypto/asn1/a_enum.c
index c7d3a9a0ac4..0952e049db8 100644
--- a/lib/libcrypto/asn1/a_enum.c
+++ b/lib/libcrypto/asn1/a_enum.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: a_enum.c,v 1.19 2018/04/25 11:48:21 tb Exp $ */
+/* $OpenBSD: a_enum.c,v 1.20 2019/04/28 05:05:56 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -56,6 +56,7 @@
* [including the GNU Public Licence.]
*/
+#include <limits.h>
#include <stdio.h>
#include <openssl/asn1.h>
@@ -107,7 +108,7 @@ long
ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
{
int neg = 0, i;
- long r = 0;
+ unsigned long r = 0;
if (a == NULL)
return (0L);
@@ -128,9 +129,13 @@ ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
r <<= 8;
r |= (unsigned char)a->data[i];
}
+
+ if (r > LONG_MAX)
+ return -1;
+
if (neg)
- r = -r;
- return (r);
+ return -(long)r;
+ return (long)r;
}
ASN1_ENUMERATED *