summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2022-07-13 20:07:45 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2022-07-13 20:07:45 +0000
commit5213fa4cb166c22a9bd0c96ee33a573eed93ed72 (patch)
tree0e1b2476b3f262faa9ae601afeb34f6f7e9aee7d
parent9a3c08d2e70465a3512241cada09817ede58b796 (diff)
Cast int64_t to uint64_t before negating.
Avoid undefined behaviour/integer overflow by casting an int64_t to uint64_t before negating. Fixes oss-fuzz #49043 ok tb@
-rw-r--r--lib/libcrypto/asn1/a_int.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/libcrypto/asn1/a_int.c b/lib/libcrypto/asn1/a_int.c
index 1f1e587d39e..d7790c787dc 100644
--- a/lib/libcrypto/asn1/a_int.c
+++ b/lib/libcrypto/asn1/a_int.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: a_int.c,v 1.43 2022/07/09 14:46:42 tb Exp $ */
+/* $OpenBSD: a_int.c,v 1.44 2022/07/13 20:07:44 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -282,14 +282,18 @@ ASN1_INTEGER_get_int64(int64_t *out_val, const ASN1_INTEGER *aint)
int
ASN1_INTEGER_set_int64(ASN1_INTEGER *aint, int64_t val)
{
+ uint64_t uval;
+
asn1_aint_clear(aint);
+ uval = (uint64_t)val;
+
if (val < 0) {
aint->type = V_ASN1_NEG_INTEGER;
- val = -val;
+ uval = -uval;
}
- return asn1_aint_set_uint64((uint64_t)val, &aint->data, &aint->length);
+ return asn1_aint_set_uint64(uval, &aint->data, &aint->length);
}
long