Coverity Fixes for issue #12531
authorNorman Ashley <nashley@cisco.com>
Tue, 4 Aug 2020 02:34:22 +0000 (12:34 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Tue, 4 Aug 2020 02:34:22 +0000 (12:34 +1000)
Fixes #12531 on master branch.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/12557)

crypto/asn1/x_algor.c
crypto/cms/cms_lib.c
crypto/x509/pcy_data.c

index 70f261502669246b79840cdc49bbc988cd459de9..f29d26d91ca5680fa5f7952205518376b9f61a01 100644 (file)
@@ -110,13 +110,18 @@ int X509_ALGOR_copy(X509_ALGOR *dest, const X509_ALGOR *src)
         if ((dest->algorithm = OBJ_dup(src->algorithm)) == NULL)
            return 0;
 
-    if (src->parameter)
+    if (src->parameter != NULL) {
+        dest->parameter = ASN1_TYPE_new();
+        if (dest->parameter == NULL)
+            return 0;
+
         /* Assuming this is also correct for a BOOL.
          * set does copy as a side effect.
          */
         if (ASN1_TYPE_set1(dest->parameter, 
               src->parameter->type, src->parameter->value.ptr) == 0)
            return 0;
+    }
 
     return 1;
 }
index 67f4fbb4eaa4e3cf21d72aeceadb91243a3102e0..6e2a20c4b3e1f798c0c5d4e3db541a107db928c5 100644 (file)
@@ -97,12 +97,12 @@ BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont)
 
     default:
         CMSerr(CMS_F_CMS_DATAINIT, CMS_R_UNSUPPORTED_TYPE);
-        return NULL;
+        goto err;
     }
 
     if (cmsbio)
         return BIO_push(cmsbio, cont);
-
+err:
     if (!icont)
         BIO_free(cont);
     return NULL;
index 966b0b2ecb3cab96544e574763c039eb3135bb1a..6b509cf457fa017f15e4fcab50fdf2340d165dd2 100644 (file)
@@ -54,6 +54,7 @@ X509_POLICY_DATA *policy_data_new(POLICYINFO *policy,
         id = NULL;
     ret = OPENSSL_zalloc(sizeof(*ret));
     if (ret == NULL) {
+        ASN1_OBJECT_free(id);
         X509V3err(X509V3_F_POLICY_DATA_NEW, ERR_R_MALLOC_FAILURE);
         return NULL;
     }