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 <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c
index 10a7cad..4f9d409 100644
--- a/crypto/x509/t_x509.c
+++ b/crypto/x509/t_x509.c
@@ -134,13 +134,12 @@
         }
 
         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)" : "";