Fix X509 propq so it does not use references
authorShane Lontis <shane.lontis@oracle.com>
Fri, 21 Aug 2020 05:14:42 +0000 (15:14 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Thu, 3 Dec 2020 22:22:24 +0000 (08:22 +1000)
Fixes #13486

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12700)

crypto/x509/x_x509.c
include/crypto/x509.h

index efcd7cd15c58e9ad420d314427109f40c22d09c5..b09fa2754ad9109f8a73c858c3855a077edb60e7 100644 (file)
@@ -95,23 +95,22 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
         ASIdentifiers_free(ret->rfc3779_asid);
 #endif
         ASN1_OCTET_STRING_free(ret->distinguishing_id);
+        OPENSSL_free(ret->propq);
         break;
 
     case ASN1_OP_DUP_POST:
         {
             X509 *old = exarg;
 
-            ret->libctx = old->libctx;
-            ret->propq = old->propq;
+            if (!x509_set0_libctx(ret, old->libctx, old->propq))
+                return 0;
         }
         break;
-
     default:
         break;
     }
 
     return 1;
-
 }
 
 ASN1_SEQUENCE_ref(X509, x509_cb) = {
@@ -149,7 +148,13 @@ int x509_set0_libctx(X509 *x, OSSL_LIB_CTX *libctx, const char *propq)
 {
     if (x != NULL) {
         x->libctx = libctx;
-        x->propq = propq;
+        OPENSSL_free(x->propq);
+        x->propq = NULL;
+        if (propq != NULL) {
+            x->propq = OPENSSL_strdup(propq);
+            if (x->propq == NULL)
+                return 0;
+        }
     }
     return 1;
 }
@@ -159,7 +164,10 @@ X509 *X509_new_ex(OSSL_LIB_CTX *libctx, const char *propq)
     X509 *cert = NULL;
 
     cert = (X509 *)ASN1_item_new((X509_it()));
-    (void)x509_set0_libctx(cert, libctx, propq);
+    if (!x509_set0_libctx(cert, libctx, propq)) {
+        X509_free(cert);
+        cert = NULL;
+    }
     return cert;
 }
 
index 6fa5d22dc6e52f8452d5e50c2eb21583d1ab8ebd..7a4ff888dc39195245de9965d309ee9438372450 100644 (file)
@@ -196,7 +196,7 @@ struct x509_st {
     ASN1_OCTET_STRING *distinguishing_id;
 
     OSSL_LIB_CTX *libctx;
-    const char *propq;
+    char *propq;
 } /* X509 */ ;
 
 /*