summaryrefslogtreecommitdiffstats
path: root/lib/libssl/src
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/libssl/src
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/libssl/src')
-rw-r--r--lib/libssl/src/crypto/asn1/asn1_mac.h17
-rw-r--r--lib/libssl/src/crypto/asn1/x_pkey.c21
2 files changed, 16 insertions, 22 deletions
diff --git a/lib/libssl/src/crypto/asn1/asn1_mac.h b/lib/libssl/src/crypto/asn1/asn1_mac.h
index 9d989eb7979..fd524dc21cc 100644
--- a/lib/libssl/src/crypto/asn1/asn1_mac.h
+++ b/lib/libssl/src/crypto/asn1/asn1_mac.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: asn1_mac.h,v 1.13 2014/06/12 15:49:27 deraadt Exp $ */
+/* $OpenBSD: asn1_mac.h,v 1.14 2014/06/27 04:41:09 miod Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -287,21 +287,6 @@ err:\
c.slen-=(c.p-c.q); \
}
-/* New macros */
-#define M_ASN1_New_Malloc(ret,type) \
- if ((ret = malloc(sizeof(type))) == NULL) \
- { c.line=__LINE__; goto err2; }
-
-#define M_ASN1_New(arg,func) \
- if (((arg)=func()) == NULL) return(NULL)
-
-#define M_ASN1_New_Error(a) \
-/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
- return(NULL);*/ \
- err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
- return(NULL)
-
-
/* BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately,
some macros that use ASN1_const_CTX still insist on writing in the input
stream. ARGH! ARGH! ARGH! Let's get rid of this macro package.
diff --git a/lib/libssl/src/crypto/asn1/x_pkey.c b/lib/libssl/src/crypto/asn1/x_pkey.c
index 2e7745315f3..bbf7666b541 100644
--- a/lib/libssl/src/crypto/asn1/x_pkey.c
+++ b/lib/libssl/src/crypto/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