Don't shift serial number into sign bit
authorDr. Stephen Henson <steve@openssl.org>
Fri, 4 Mar 2016 18:04:46 +0000 (18:04 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 7 Mar 2016 15:14:18 +0000 (15:14 +0000)
Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/asn1/t_x509.c

index 8aab55130c954580d3b6cdbacc485a791153d599..8888396f84345ed82e023a02f11bf91cfaf4b516 100644 (file)
@@ -140,7 +140,8 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
             goto err;
 
         bs = X509_get_serialNumber(x);
-        if (bs->length <= (int)sizeof(long)) {
+        if (bs->length < (int)sizeof(long)
+            || (bs->length == sizeof(long) && (bs->data[0] & 0x80) == 0)) {
             l = ASN1_INTEGER_get(bs);
             if (bs->type == V_ASN1_NEG_INTEGER) {
                 l = -l;