Avoid signed overflow
authorKurt Roeckx <kurt@roeckx.be>
Thu, 23 Jun 2016 07:37:51 +0000 (09:37 +0200)
committerRichard Levitte <levitte@openssl.org>
Mon, 20 Mar 2017 21:10:54 +0000 (22:10 +0100)
Found by afl

Reviewed-by: Rich Salz <rsalz@openssl.org>
MR: #3013
(cherry picked from commit 5bea15ebb359c91a1bb7569620ead14bb71cfb81)

crypto/asn1/x_long.c

index 3aed44a3ddf753c63ebbf6738749ace5656db675..98562a18ba9eebe535a9ef34210771374499890e 100644 (file)
@@ -178,8 +178,8 @@ static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
     }
     ltmp = (long)utmp;
     if (neg) {
-        ltmp++;
         ltmp = -ltmp;
+        ltmp--;
     }
     if (ltmp == it->size) {
         ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);