From 6196faba8a9770a9410b7b5175745b015f6eb3ae Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Thu, 24 Feb 2022 12:35:03 -0500 Subject: [PATCH] Replace an ASN1_INTEGER_get call with ASN1_INTEGER_get_uint64 This gives clearer, less platform-dependent behavior. Change-Id: Ib935bf861108ec010d8d409d840f94b52a3b3ae0 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/51635 Reviewed-by: Adam Langley Commit-Queue: David Benjamin --- crypto/x509/t_x509.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c index 10a7cad602..4f9d40979a 100644 --- a/crypto/x509/t_x509.c +++ b/crypto/x509/t_x509.c @@ -134,13 +134,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, } const ASN1_INTEGER *serial = X509_get0_serialNumber(x); - /* |ASN1_INTEGER_get| returns -1 on overflow, so this check skips - * negative and large serial numbers. */ - l = ASN1_INTEGER_get(serial); - if (l >= 0) { + uint64_t serial_u64; + if (ASN1_INTEGER_get_uint64(&serial_u64, serial)) { assert(serial->type != V_ASN1_NEG_INTEGER); - if (BIO_printf(bp, " %ld (0x%lx)\n", l, (unsigned long)l) <= 0) { - goto err; + if (BIO_printf(bp, " %" PRIu64 " (0x%" PRIx64 ")\n", serial_u64, + serial_u64) <= 0) { + goto err; } } else { neg = (serial->type == V_ASN1_NEG_INTEGER) ? " (Negative)" : "";