3852e3
From 2f7530077e0ef79d98718138716bc51ca0cad658 Mon Sep 17 00:00:00 2001
3852e3
From: Hugo Landau <hlandau@openssl.org>
3852e3
Date: Tue, 17 Jan 2023 17:45:42 +0000
3852e3
Subject: [PATCH 14/18] CVE-2023-0286: Fix GENERAL_NAME_cmp for x400Address
3852e3
 (3.0)
3852e3
3852e3
Reviewed-by: Paul Dale <pauli@openssl.org>
3852e3
Reviewed-by: Tomas Mraz <tomas@openssl.org>
3852e3
---
3852e3
 CHANGES.md                  | 19 +++++++++++++++++++
3852e3
 crypto/x509/v3_genn.c       |  2 +-
3852e3
 include/openssl/x509v3.h.in |  2 +-
3852e3
 test/v3nametest.c           |  8 ++++++++
3852e3
 4 files changed, 29 insertions(+), 2 deletions(-)
3852e3
3852e3
diff --git a/crypto/x509/v3_genn.c b/crypto/x509/v3_genn.c
3852e3
index c0a7166cd0..1741c2d2f6 100644
3852e3
--- a/crypto/x509v3/v3_genn.c
3852e3
+++ b/crypto/x509v3/v3_genn.c
3852e3
@@ -98,7 +98,7 @@ int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b)
3852e3
         return -1;
3852e3
     switch (a->type) {
3852e3
     case GEN_X400:
3852e3
-        result = ASN1_TYPE_cmp(a->d.x400Address, b->d.x400Address);
3852e3
+        result = ASN1_STRING_cmp(a->d.x400Address, b->d.x400Address);
3852e3
         break;
3852e3
 
3852e3
     case GEN_EDIPARTY:
3852e3
diff --git a/crypto/x509v3/x509v3.h b/crypto/x509v3/x509v3.h
3852e3
index d00a66a343..c087e3cf92 100644
3852e3
--- a/crypto/x509v3/x509v3.h
3852e3
+++ b/crypto/x509v3/x509v3.h
3852e3
@@ -154,7 +154,7 @@ typedef struct GENERAL_NAME_st {
3852e3
         OTHERNAME *otherName;   /* otherName */
3852e3
         ASN1_IA5STRING *rfc822Name;
3852e3
         ASN1_IA5STRING *dNSName;
3852e3
-        ASN1_TYPE *x400Address;
3852e3
+        ASN1_STRING *x400Address;
3852e3
         X509_NAME *directoryName;
3852e3
         EDIPARTYNAME *ediPartyName;
3852e3
         ASN1_IA5STRING *uniformResourceIdentifier;
3852e3
diff --git a/crypto/x509v3/v3nametest.c b/crypto/x509v3/v3nametest.c
3852e3
index 6d2e2f8e27..0341995dde 100644
3852e3
--- a/crypto/x509v3/v3nametest.c
3852e3
+++ b/crypto/x509v3/v3nametest.c
3852e3
@@ -644,6 +644,14 @@ static struct gennamedata {
3852e3
             0xb7, 0x09, 0x02, 0x02
3852e3
         },
3852e3
         15
3852e3
+    }, {
3852e3
+        /*
3852e3
+         * Regression test for CVE-2023-0286.
3852e3
+         */
3852e3
+        {
3852e3
+            0xa3, 0x00
3852e3
+        },
3852e3
+        2
3852e3
     }
3852e3
 };
3852e3
 
3852e3
-- 
3852e3
2.39.1
3852e3