summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2015-07-20 15:27:01 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2015-07-20 15:27:01 +0000
commitf4deafa8e772a3698cb16a811d59cfdf42050702 (patch)
treeb3c7cea9b1ae7c5061ff8c073d7c64e2acb23763
parentf6a32d30bb9d969e19c4d4522d030d591abb0b13 (diff)
In X509_PKEY_new(), make sure all allocation failures push an error to the
error stack, not only the first one. ok guenther@ doug@
-rw-r--r--lib/libssl/src/crypto/asn1/x_pkey.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/libssl/src/crypto/asn1/x_pkey.c b/lib/libssl/src/crypto/asn1/x_pkey.c
index 9523740af72..e421edbe8d3 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.16 2015/04/12 15:15:51 doug Exp $ */
+/* $OpenBSD: x_pkey.c,v 1.17 2015/07/20 15:27:00 miod Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -73,17 +73,18 @@ X509_PKEY_new(void)
if ((ret = malloc(sizeof(X509_PKEY))) == NULL) {
ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
__LINE__);
- return NULL;
+ goto err;
}
ret->version = 0;
if ((ret->enc_algor = X509_ALGOR_new()) == NULL) {
- free(ret);
- return NULL;
+ ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
+ __LINE__);
+ goto err;
}
if ((ret->enc_pkey = M_ASN1_OCTET_STRING_new()) == NULL) {
- X509_ALGOR_free(ret->enc_algor);
- free(ret);
- return NULL;
+ ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
+ __LINE__);
+ goto err;
}
ret->dec_pkey = NULL;
ret->key_length = 0;
@@ -93,6 +94,13 @@ X509_PKEY_new(void)
memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
ret->references = 1;
return (ret);
+
+err:
+ if (ret) {
+ X509_ALGOR_free(ret->enc_algor);
+ free(ret);
+ }
+ return NULL;
}
void