Print the X509 version signed, and convert to unsigned for the hex version.
authorKurt Roeckx <kurt@roeckx.be>
Thu, 20 Oct 2016 18:49:22 +0000 (20:49 +0200)
committerKurt Roeckx <kurt@roeckx.be>
Tue, 10 Jan 2017 21:27:37 +0000 (22:27 +0100)
Found by tis-interpreter

Reviewed-by: Rich Salz <rsalz@openssl.org>
GH: #1754

crypto/x509/t_x509.c

index feeff754c3d26bc896d94a2babf84660af427a37..ce670460ee3b090d5ef1441da49513d81625df3f 100644 (file)
@@ -71,8 +71,13 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
     }
     if (!(cflag & X509_FLAG_NO_VERSION)) {
         l = X509_get_version(x);
-        if (BIO_printf(bp, "%8sVersion: %lu (0x%lx)\n", "", l + 1, l) <= 0)
-            goto err;
+        if (l >= 0 && l <= 2) {
+            if (BIO_printf(bp, "%8sVersion: %ld (0x%lx)\n", "", l + 1, (unsigned long)l) <= 0)
+                goto err;
+        } else {
+            if (BIO_printf(bp, "%8sVersion: Unknown (%ld)\n", "", l) <= 0)
+                goto err;
+        }
     }
     if (!(cflag & X509_FLAG_NO_SERIAL)) {