summaryrefslogtreecommitdiffstats
path: root/lib/libcrypto/asn1/x_pkey.c
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2014-06-27 04:41:09 +0000
committermiod <miod@openbsd.org>2014-06-27 04:41:09 +0000
commit69290ac13c232e2b598637c8ed284131824546df (patch)
tree30cb853f368339e20098def828b3d700f0fc9e30 /lib/libcrypto/asn1/x_pkey.c
parentAdd back an #ifndef MAP_INHERIT_ZERO chunk to support the old getpid() (diff)
downloadwireguard-openbsd-69290ac13c232e2b598637c8ed284131824546df.tar.xz
wireguard-openbsd-69290ac13c232e2b598637c8ed284131824546df.zip
Remove M_ASN1_New* macros which are only used in X509_PKEY_new() are obfuscate
it to hide memory leaks in the error paths, and fix aforementioned memory leaks. ok jsing@ logan@ deraadt@
Diffstat (limited to 'lib/libcrypto/asn1/x_pkey.c')
-rw-r--r--lib/libcrypto/asn1/x_pkey.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/libcrypto/asn1/x_pkey.c b/lib/libcrypto/asn1/x_pkey.c
index 2e7745315f3..bbf7666b541 100644
--- a/lib/libcrypto/asn1/x_pkey.c
+++ b/lib/libcrypto/asn1/x_pkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: x_pkey.c,v 1.11 2014/06/12 15:49:27 deraadt Exp $ */
+/* $OpenBSD: x_pkey.c,v 1.12 2014/06/27 04:41:09 miod Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -107,12 +107,22 @@ X509_PKEY *
X509_PKEY_new(void)
{
X509_PKEY *ret = NULL;
- ASN1_CTX c;
- M_ASN1_New_Malloc(ret, X509_PKEY);
+ if ((ret = malloc(sizeof(X509_PKEY))) == NULL) {
+ ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
+ __LINE__);
+ return NULL;
+ }
ret->version = 0;
- M_ASN1_New(ret->enc_algor, X509_ALGOR_new);
- M_ASN1_New(ret->enc_pkey, M_ASN1_OCTET_STRING_new);
+ if ((ret->enc_algor = X509_ALGOR_new()) == NULL) {
+ free(ret);
+ return NULL;
+ }
+ if ((ret->enc_pkey = M_ASN1_OCTET_STRING_new()) == NULL) {
+ X509_ALGOR_free(ret->enc_algor);
+ free(ret);
+ return NULL;
+ }
ret->dec_pkey = NULL;
ret->key_length = 0;
ret->key_data = NULL;
@@ -121,7 +131,6 @@ X509_PKEY_new(void)
memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
ret->references = 1;
return (ret);
- M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
}
void