summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiod <>2015-07-20 15:27:00 +0000
committermiod <>2015-07-20 15:27:00 +0000
commita1e161dab09914b53d120c7ca6cce1b44e5b0ee0 (patch)
tree4c8946ef9c63862bef887e0d9ac32ca18bdc86ef
parent64f9d6038d7492dd3e5c94e3104ca474fad44390 (diff)
downloadopenbsd-a1e161dab09914b53d120c7ca6cce1b44e5b0ee0.tar.gz
openbsd-a1e161dab09914b53d120c7ca6cce1b44e5b0ee0.tar.bz2
openbsd-a1e161dab09914b53d120c7ca6cce1b44e5b0ee0.zip
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--src/lib/libcrypto/asn1/x_pkey.c22
-rw-r--r--src/lib/libssl/src/crypto/asn1/x_pkey.c22
2 files changed, 30 insertions, 14 deletions
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
index 9523740af7..e421edbe8d 100644
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_pkey.c,v 1.16 2015/04/12 15:15:51 doug Exp $ */ 1/* $OpenBSD: x_pkey.c,v 1.17 2015/07/20 15:27:00 miod Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -73,17 +73,18 @@ X509_PKEY_new(void)
73 if ((ret = malloc(sizeof(X509_PKEY))) == NULL) { 73 if ((ret = malloc(sizeof(X509_PKEY))) == NULL) {
74 ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE, 74 ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
75 __LINE__); 75 __LINE__);
76 return NULL; 76 goto err;
77 } 77 }
78 ret->version = 0; 78 ret->version = 0;
79 if ((ret->enc_algor = X509_ALGOR_new()) == NULL) { 79 if ((ret->enc_algor = X509_ALGOR_new()) == NULL) {
80 free(ret); 80 ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
81 return NULL; 81 __LINE__);
82 goto err;
82 } 83 }
83 if ((ret->enc_pkey = M_ASN1_OCTET_STRING_new()) == NULL) { 84 if ((ret->enc_pkey = M_ASN1_OCTET_STRING_new()) == NULL) {
84 X509_ALGOR_free(ret->enc_algor); 85 ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
85 free(ret); 86 __LINE__);
86 return NULL; 87 goto err;
87 } 88 }
88 ret->dec_pkey = NULL; 89 ret->dec_pkey = NULL;
89 ret->key_length = 0; 90 ret->key_length = 0;
@@ -93,6 +94,13 @@ X509_PKEY_new(void)
93 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH); 94 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
94 ret->references = 1; 95 ret->references = 1;
95 return (ret); 96 return (ret);
97
98err:
99 if (ret) {
100 X509_ALGOR_free(ret->enc_algor);
101 free(ret);
102 }
103 return NULL;
96} 104}
97 105
98void 106void
diff --git a/src/lib/libssl/src/crypto/asn1/x_pkey.c b/src/lib/libssl/src/crypto/asn1/x_pkey.c
index 9523740af7..e421edbe8d 100644
--- a/src/lib/libssl/src/crypto/asn1/x_pkey.c
+++ b/src/lib/libssl/src/crypto/asn1/x_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_pkey.c,v 1.16 2015/04/12 15:15:51 doug Exp $ */ 1/* $OpenBSD: x_pkey.c,v 1.17 2015/07/20 15:27:00 miod Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -73,17 +73,18 @@ X509_PKEY_new(void)
73 if ((ret = malloc(sizeof(X509_PKEY))) == NULL) { 73 if ((ret = malloc(sizeof(X509_PKEY))) == NULL) {
74 ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE, 74 ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
75 __LINE__); 75 __LINE__);
76 return NULL; 76 goto err;
77 } 77 }
78 ret->version = 0; 78 ret->version = 0;
79 if ((ret->enc_algor = X509_ALGOR_new()) == NULL) { 79 if ((ret->enc_algor = X509_ALGOR_new()) == NULL) {
80 free(ret); 80 ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
81 return NULL; 81 __LINE__);
82 goto err;
82 } 83 }
83 if ((ret->enc_pkey = M_ASN1_OCTET_STRING_new()) == NULL) { 84 if ((ret->enc_pkey = M_ASN1_OCTET_STRING_new()) == NULL) {
84 X509_ALGOR_free(ret->enc_algor); 85 ASN1_MAC_H_err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE,
85 free(ret); 86 __LINE__);
86 return NULL; 87 goto err;
87 } 88 }
88 ret->dec_pkey = NULL; 89 ret->dec_pkey = NULL;
89 ret->key_length = 0; 90 ret->key_length = 0;
@@ -93,6 +94,13 @@ X509_PKEY_new(void)
93 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH); 94 memset(ret->cipher.iv, 0, EVP_MAX_IV_LENGTH);
94 ret->references = 1; 95 ret->references = 1;
95 return (ret); 96 return (ret);
97
98err:
99 if (ret) {
100 X509_ALGOR_free(ret->enc_algor);
101 free(ret);
102 }
103 return NULL;
96} 104}
97 105
98void 106void