summaryrefslogtreecommitdiff
path: root/ext/openssl/openssl.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2017-02-02 13:06:31 +0100
committerAnatol Belski <ab@php.net>2017-02-02 13:06:31 +0100
commit9b9080e85d7d7ecaa743ec84e90bb0b52a51029f (patch)
tree62b6fa0a88f3ade77eb002ea2f4a53a5e6943585 /ext/openssl/openssl.c
parent0260d42f6d0752f9255ced9d1d5f396d973ef676 (diff)
parent6fc0ae638acd2a66a4181078f4ac5d789762d9de (diff)
downloadphp-git-9b9080e85d7d7ecaa743ec84e90bb0b52a51029f.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fixed #74022 PHP Fast CGI crashes when reading from a pfx file.
Diffstat (limited to 'ext/openssl/openssl.c')
-rw-r--r--ext/openssl/openssl.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 47a28a1111..8de329aec7 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -2935,52 +2935,53 @@ PHP_FUNCTION(openssl_pkcs12_read)
zval_dtor(zout);
array_init(zout);
- bio_out = BIO_new(BIO_s_mem());
- if (PEM_write_bio_X509(bio_out, cert)) {
- BUF_MEM *bio_buf;
- BIO_get_mem_ptr(bio_out, &bio_buf);
- ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
- add_assoc_zval(zout, "cert", &zcert);
- } else {
- php_openssl_store_errors();
+ if (cert) {
+ bio_out = BIO_new(BIO_s_mem());
+ if (PEM_write_bio_X509(bio_out, cert)) {
+ BUF_MEM *bio_buf;
+ BIO_get_mem_ptr(bio_out, &bio_buf);
+ ZVAL_STRINGL(&zcert, bio_buf->data, bio_buf->length);
+ add_assoc_zval(zout, "cert", &zcert);
+ } else {
+ php_openssl_store_errors();
+ }
+ BIO_free(bio_out);
}
- BIO_free(bio_out);
- bio_out = BIO_new(BIO_s_mem());
- if (PEM_write_bio_PrivateKey(bio_out, pkey, NULL, NULL, 0, 0, NULL)) {
- BUF_MEM *bio_buf;
- BIO_get_mem_ptr(bio_out, &bio_buf);
- ZVAL_STRINGL(&zpkey, bio_buf->data, bio_buf->length);
- add_assoc_zval(zout, "pkey", &zpkey);
- } else {
- php_openssl_store_errors();
+ if (pkey) {
+ bio_out = BIO_new(BIO_s_mem());
+ if (PEM_write_bio_PrivateKey(bio_out, pkey, NULL, NULL, 0, 0, NULL)) {
+ BUF_MEM *bio_buf;
+ BIO_get_mem_ptr(bio_out, &bio_buf);
+ ZVAL_STRINGL(&zpkey, bio_buf->data, bio_buf->length);
+ add_assoc_zval(zout, "pkey", &zpkey);
+ } else {
+ php_openssl_store_errors();
+ }
+ BIO_free(bio_out);
}
- BIO_free(bio_out);
- array_init(&zextracerts);
+ if (ca && sk_X509_num(ca)) {
+ array_init(&zextracerts);
- for (i=0;;i++) {
- zval zextracert;
- X509* aCA = sk_X509_pop(ca);
- if (!aCA) break;
+ for (i = 0; i < sk_X509_num(ca); i++) {
+ zval zextracert;
+ X509* aCA = sk_X509_pop(ca);
+ if (!aCA) break;
- bio_out = BIO_new(BIO_s_mem());
- if (PEM_write_bio_X509(bio_out, aCA)) {
- BUF_MEM *bio_buf;
- BIO_get_mem_ptr(bio_out, &bio_buf);
- ZVAL_STRINGL(&zextracert, bio_buf->data, bio_buf->length);
- add_index_zval(&zextracerts, i, &zextracert);
+ bio_out = BIO_new(BIO_s_mem());
+ if (PEM_write_bio_X509(bio_out, aCA)) {
+ BUF_MEM *bio_buf;
+ BIO_get_mem_ptr(bio_out, &bio_buf);
+ ZVAL_STRINGL(&zextracert, bio_buf->data, bio_buf->length);
+ add_index_zval(&zextracerts, i, &zextracert);
+ }
+ X509_free(aCA);
}
- BIO_free(bio_out);
- X509_free(aCA);
- }
- if(ca) {
sk_X509_free(ca);
add_assoc_zval(zout, "extracerts", &zextracerts);
- } else {
- zval_dtor(&zextracerts);
}
RETVAL_TRUE;