From 464c1639ae544e3952823caf169d2e4199a32fc3 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 18 May 2017 12:03:13 +0200 Subject: follow up fix on bug #74022 --- ext/openssl/openssl.c | 6 ++++-- ext/openssl/tests/bug74022_2.phpt | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 ext/openssl/tests/bug74022_2.phpt diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 15b4750537..9f3521f5e6 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -2795,6 +2795,7 @@ PHP_FUNCTION(openssl_pkcs12_read) if(d2i_PKCS12_bio(bio_in, &p12)) { if(PKCS12_parse(p12, pass, &pkey, &cert, &ca)) { BIO * bio_out; + int cert_num; zval_dtor(zout); array_init(zout); @@ -2821,11 +2822,12 @@ PHP_FUNCTION(openssl_pkcs12_read) BIO_free(bio_out); } - if (ca && sk_X509_num(ca)) { + cert_num = sk_X509_num(ca); + if (ca && cert_num > 0) { array_init(&zextracerts); - for (i=0; i < sk_X509_num(ca); i++) { + for (i=0; i < cert_num; i++) { zval zextracert; X509* aCA = sk_X509_pop(ca); if (!aCA) break; diff --git a/ext/openssl/tests/bug74022_2.phpt b/ext/openssl/tests/bug74022_2.phpt new file mode 100644 index 0000000000..65d0977674 --- /dev/null +++ b/ext/openssl/tests/bug74022_2.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #74022 PHP Fast CGI crashes when reading from a pfx file with valid password, multiple extra certs +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECTF-- +int(2) +===DONE=== -- cgit v1.2.1