diff options
| author | jsing <> | 2022-07-13 20:07:44 +0000 |
|---|---|---|
| committer | jsing <> | 2022-07-13 20:07:44 +0000 |
| commit | aab46b2cb1dcc736abbfa0465c423ddc885c72e9 (patch) | |
| tree | 4b3a214761d37c35bd5bb3f924bb0329a9e48d7d /src | |
| parent | 9d6b33fca1ce346e7dc2cd7c88e9e7c22879516d (diff) | |
| download | openbsd-aab46b2cb1dcc736abbfa0465c423ddc885c72e9.tar.gz openbsd-aab46b2cb1dcc736abbfa0465c423ddc885c72e9.tar.bz2 openbsd-aab46b2cb1dcc736abbfa0465c423ddc885c72e9.zip | |
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@
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_int.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c index 1f1e587d39..d7790c787d 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.43 2022/07/09 14:46:42 tb Exp $ */ | 1 | /* $OpenBSD: a_int.c,v 1.44 2022/07/13 20:07:44 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 | * |
| @@ -282,14 +282,18 @@ ASN1_INTEGER_get_int64(int64_t *out_val, const ASN1_INTEGER *aint) | |||
| 282 | int | 282 | int |
| 283 | ASN1_INTEGER_set_int64(ASN1_INTEGER *aint, int64_t val) | 283 | ASN1_INTEGER_set_int64(ASN1_INTEGER *aint, int64_t val) |
| 284 | { | 284 | { |
| 285 | uint64_t uval; | ||
| 286 | |||
| 285 | asn1_aint_clear(aint); | 287 | asn1_aint_clear(aint); |
| 286 | 288 | ||
| 289 | uval = (uint64_t)val; | ||
| 290 | |||
| 287 | if (val < 0) { | 291 | if (val < 0) { |
| 288 | aint->type = V_ASN1_NEG_INTEGER; | 292 | aint->type = V_ASN1_NEG_INTEGER; |
| 289 | val = -val; | 293 | uval = -uval; |
| 290 | } | 294 | } |
| 291 | 295 | ||
| 292 | return asn1_aint_set_uint64((uint64_t)val, &aint->data, &aint->length); | 296 | return asn1_aint_set_uint64(uval, &aint->data, &aint->length); |
| 293 | } | 297 | } |
| 294 | 298 | ||
| 295 | long | 299 | long |
