Rewrite X509_PKEY_new to avoid old ASN1. macros.
authorDr. Stephen Henson <steve@openssl.org>
Sat, 28 Mar 2015 15:25:46 +0000 (15:25 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 30 Mar 2015 21:01:31 +0000 (22:01 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/asn1/x_pkey.c

index 2b131e4..98e4a3d 100644 (file)
 #include "cryptlib.h"
 #include <openssl/evp.h>
 #include <openssl/objects.h>
-#include <openssl/asn1_mac.h>
 #include <openssl/x509.h>
 
 X509_PKEY *X509_PKEY_new(void)
 {
     X509_PKEY *ret = NULL;
-    ASN1_CTX c;
 
-    M_ASN1_New_Malloc(ret, X509_PKEY);
+    ret = OPENSSL_malloc(sizeof(X509_PKEY));
+    if (!ret)
+        goto err;
+    memset(ret, 0, sizeof(X509_PKEY));
+
     ret->version = 0;
-    M_ASN1_New(ret->enc_algor, X509_ALGOR_new);
-    M_ASN1_New(ret->enc_pkey, ASN1_OCTET_STRING_new);
+    ret->enc_algor = X509_ALGOR_new();
+    ret->enc_pkey = ASN1_OCTET_STRING_new();
+    if (!ret->enc_algor || !ret->enc_pkey)
+        goto err;
     ret->dec_pkey = NULL;
     ret->key_length = 0;
     ret->key_data = NULL;
@@ -79,8 +83,11 @@ X509_PKEY *X509_PKEY_new(void)
     ret->cipher.cipher = NULL;
     memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
     ret->references = 1;
-    return (ret);
-    M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
+    return ret;
+err:
+    X509_PKEY_free(ret);
+    ASN1err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE);
+    return NULL;
 }
 
 void X509_PKEY_free(X509_PKEY *x)