From b17d15f07ab02b8449db096eaafa56e93b242dee Mon Sep 17 00:00:00 2001 From: Kurt Roeckx Date: Sat, 14 Jan 2017 15:58:42 +0100 Subject: [PATCH] Fix undefined behaviour when printing the X509 serial Found by afl Reviewed-by: Andy Polyakov GH: #2230 (cherry picked from commit 244d7b288f2b9ab7f6a2dbf068eccd6e20d9eef6) --- crypto/x509/t_x509.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c index ce670460ee..5119c0e6f7 100644 --- a/crypto/x509/t_x509.c +++ b/crypto/x509/t_x509.c @@ -93,12 +93,14 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, l = -1; } if (l != -1) { + unsigned long ul; if (bs->type == V_ASN1_NEG_INTEGER) { - l = -l; + ul = 0 - (unsigned long)l; neg = "-"; } else + ul = l; neg = ""; - if (BIO_printf(bp, " %s%lu (%s0x%lx)\n", neg, l, neg, l) <= 0) + if (BIO_printf(bp, " %s%lu (%s0x%lx)\n", neg, ul, neg, ul) <= 0) goto err; } else { neg = (bs->type == V_ASN1_NEG_INTEGER) ? " (Negative)" : ""; -- 2.25.1