From 94f4b4b31314c07a4b6c9898e14c1023a112d0d0 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sat, 28 Mar 2015 15:25:46 +0000 Subject: [PATCH] Rewrite X509_PKEY_new to avoid old ASN1. macros. Reviewed-by: Rich Salz --- crypto/asn1/x_pkey.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/crypto/asn1/x_pkey.c b/crypto/asn1/x_pkey.c index 2b131e4a59..98e4a3d491 100644 --- a/crypto/asn1/x_pkey.c +++ b/crypto/asn1/x_pkey.c @@ -60,18 +60,22 @@ #include "cryptlib.h" #include #include -#include #include 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)