Reject decoding of an INT64 with a value >INT64_MAX
authorMatt Caswell <matt@openssl.org>
Mon, 10 Apr 2017 16:33:29 +0000 (17:33 +0100)
committerMatt Caswell <matt@openssl.org>
Tue, 11 Apr 2017 14:34:04 +0000 (15:34 +0100)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3159)
(cherry picked from commit 0856e3f167964f58c26796331eab9d8b0a883921)

crypto/asn1/x_int64.c

index e0520ffa2de31e70db936b7e559e2b93ad236227..26578b29c0e857328bcbf424d9c29ce97830c54c 100644 (file)
@@ -71,6 +71,11 @@ static int uint64_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
         ASN1err(ASN1_F_UINT64_C2I, ASN1_R_ILLEGAL_NEGATIVE_VALUE);
         return 0;
     }
+    if ((it->size & INTxx_FLAG_SIGNED) == INTxx_FLAG_SIGNED
+            && !neg && utmp > INT64_MAX) {
+        ASN1err(ASN1_F_UINT64_C2I, ASN1_R_TOO_LARGE);
+        return 0;
+    }
     memcpy(cp, &utmp, sizeof(utmp));
     return 1;
 }