diff options
author | jsing <> | 2022-06-28 19:44:28 +0000 |
---|---|---|
committer | jsing <> | 2022-06-28 19:44:28 +0000 |
commit | 8705fa453d4cc966cbe069c41ff6fda3ab038581 (patch) | |
tree | 49119ef2899ea30bdf9890fb1dd0fd5ae2e274be | |
parent | 4b57b59ced3d3988203fa4192fa308ecd157c506 (diff) | |
download | openbsd-8705fa453d4cc966cbe069c41ff6fda3ab038581.tar.gz openbsd-8705fa453d4cc966cbe069c41ff6fda3ab038581.tar.bz2 openbsd-8705fa453d4cc966cbe069c41ff6fda3ab038581.zip |
Negate unsigned then cast to signed.
Avoid undefined behaviour by negating the unsigned value, before casting
to int64_t, rather than casting to int64_t then negating.
Fixes oss-fuzz #48499
ok tb@
-rw-r--r-- | src/lib/libcrypto/asn1/a_int.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c index 546713ae46..38a2e1cfa5 100644 --- a/src/lib/libcrypto/asn1/a_int.c +++ b/src/lib/libcrypto/asn1/a_int.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_int.c,v 1.41 2022/06/25 15:39:12 jsing Exp $ */ | 1 | /* $OpenBSD: a_int.c,v 1.42 2022/06/28 19:44:28 jsing 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 | * |
@@ -207,7 +207,7 @@ asn1_aint_get_int64(CBS *cbs, int negative, int64_t *out_val) | |||
207 | ASN1error(ASN1_R_TOO_SMALL); | 207 | ASN1error(ASN1_R_TOO_SMALL); |
208 | return 0; | 208 | return 0; |
209 | } | 209 | } |
210 | *out_val = -(int64_t)val; | 210 | *out_val = (int64_t)-val; |
211 | } else { | 211 | } else { |
212 | if (val > (uint64_t)INT64_MAX) { | 212 | if (val > (uint64_t)INT64_MAX) { |
213 | ASN1error(ASN1_R_TOO_LARGE); | 213 | ASN1error(ASN1_R_TOO_LARGE); |