From 649494c0ee54102ac4a6c62fd5faf38143efb107 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Wed, 17 May 2017 19:56:49 +0200 Subject: [PATCH 1/2] Fixed bug #74606 (Segfault within try/catch/finally nesting in Generators) Thanks to Nikita for pointing out the error source. --- NEWS | 2 ++ Zend/tests/generators/bug74606.phpt | 29 +++++++++++++++++++++++++++++ Zend/zend_generators.c | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/generators/bug74606.phpt diff --git a/NEWS b/NEWS index fcc0f40bafd..e5cafc9329f 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ PHP NEWS . Fixed bug #74546 (SIGILL in ZEND_FETCH_CLASS_CONSTANT_SPEC_CONST_CONST). (Laruence) . Fixed bug #74589 (__DIR__ wrong for unicode character). (Anatol) + . Fixed bug #74606 (Segfault within try/catch/finally nesting in Generators). + (Bob, Nikita) - intl: . Fixed bug #74468 (wrong reflection on Collator::sortWithSortKeys). (villfa) diff --git a/Zend/tests/generators/bug74606.phpt b/Zend/tests/generators/bug74606.phpt new file mode 100644 index 00000000000..cfb7f7f8cd8 --- /dev/null +++ b/Zend/tests/generators/bug74606.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #74606 (Segfault within try/catch/finally nesting in Generators) +--FILE-- +throw(new Exception); + +?> +--EXPECT-- +fin foo +catch +fin bar diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 945c3615edc..99145ada717 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -108,7 +108,7 @@ static void zend_generator_cleanup_unfinished_execution( if (UNEXPECTED(generator->frozen_call_stack)) { zend_generator_restore_call_stack(generator); } - zend_cleanup_unfinished_execution(execute_data, op_num, 0); + zend_cleanup_unfinished_execution(execute_data, op_num, catch_op_num); } } /* }}} */ From 464c1639ae544e3952823caf169d2e4199a32fc3 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 18 May 2017 12:03:13 +0200 Subject: [PATCH 2/2] 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 15b4750537a..9f3521f5e64 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 00000000000..65d0977674f --- /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===