From 2863f46d6897b58fdd0e562f732118b813523a36 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 27 Oct 2015 13:18:50 +0000 Subject: [PATCH 01/65] Fixed typo in reflection phpt --- ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt b/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt index 900ce21d45..bbe5fdbaec 100644 --- a/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt +++ b/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt @@ -5,7 +5,7 @@ Stefan Koopmanschap TestFest PHP|Tek --SKIPIF-- --FILE-- Date: Tue, 27 Oct 2015 17:26:36 +0100 Subject: [PATCH 02/65] fixed typo in comment introduced in eb32da13cd4f5dd0dae0e07a8f0b6c42d5678f5f --- Zend/zend_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 06cda75363..6d8edbca4d 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -1465,7 +1465,7 @@ static void *zend_mm_realloc_heap(zend_mm_heap *heap, void *ptr, size_t size, si #ifdef ZEND_WIN32 /* On Windows we don't have ability to extend huge block in-place. * We allocate them with 2MB size granularuty, to avoid many - * reallocatioons whenthey when they are extended by small peaces + * reallocatioons when they are extended by small peaces */ new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); #else From b83782e6824a1e1bf132dfe94e5946b1ae66df1f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 27 Oct 2015 17:27:57 +0100 Subject: [PATCH 03/65] fixed another comment typo --- Zend/zend_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 6d8edbca4d..3057eebb1d 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -1733,7 +1733,7 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D #ifdef ZEND_WIN32 /* On Windows we don't have ability to extend huge block in-place. * We allocate them with 2MB size granularuty, to avoid many - * reallocatioons whenthey when they are extended by small peaces + * reallocatioons when they are extended by small peaces */ size_t new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); #else From 08c97ea0a1fef2813127ea50ffeaa017cc947d0f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 27 Oct 2015 17:29:28 +0100 Subject: [PATCH 04/65] fixed typo --- Zend/zend_alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 3057eebb1d..4e9102ce35 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -1463,9 +1463,9 @@ static void *zend_mm_realloc_heap(zend_mm_heap *heap, void *ptr, size_t size, si size = real_size; #endif #ifdef ZEND_WIN32 - /* On Windows we don't have ability to extend huge block in-place. + /* On Windows we don't have ability to extend huge blocks in-place. * We allocate them with 2MB size granularuty, to avoid many - * reallocatioons when they are extended by small peaces + * reallocations when they are extended by small pieces */ new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); #else @@ -1731,9 +1731,9 @@ static void zend_mm_change_huge_block_size(zend_mm_heap *heap, void *ptr, size_t static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) { #ifdef ZEND_WIN32 - /* On Windows we don't have ability to extend huge block in-place. + /* On Windows we don't have ability to extend huge blocks in-place. * We allocate them with 2MB size granularuty, to avoid many - * reallocatioons when they are extended by small peaces + * reallocations when they are extended by small pieces */ size_t new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); #else From a4d5accf7d227141ff9e315767fb39be8526e89f Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 28 Oct 2015 11:21:15 +0800 Subject: [PATCH 05/65] rm duplicate include --- sapi/cgi/cgi_main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 6293470472..63f7dfca6b 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -31,7 +31,6 @@ #include "SAPI.h" #include -#include "php.h" #ifdef PHP_WIN32 # include "win32/time.h" From 8e83ea6e5df1f3678195511bf215e1de719c0512 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 28 Oct 2015 09:03:16 +0100 Subject: [PATCH 06/65] fixed another comment typo --- Zend/zend_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 4e9102ce35..c9d4de43a4 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -1464,7 +1464,7 @@ static void *zend_mm_realloc_heap(zend_mm_heap *heap, void *ptr, size_t size, si #endif #ifdef ZEND_WIN32 /* On Windows we don't have ability to extend huge blocks in-place. - * We allocate them with 2MB size granularuty, to avoid many + * We allocate them with 2MB size granularity, to avoid many * reallocations when they are extended by small pieces */ new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); @@ -1732,7 +1732,7 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D { #ifdef ZEND_WIN32 /* On Windows we don't have ability to extend huge blocks in-place. - * We allocate them with 2MB size granularuty, to avoid many + * We allocate them with 2MB size granularity, to avoid many * reallocations when they are extended by small pieces */ size_t new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); From 37ed0dafe47fb1053aee7822113bacc1f213337a Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 2 Nov 2015 10:47:02 +0800 Subject: [PATCH 07/65] Fixed bug #70828 (php-fpm 5.6 with opcache crashes when referencing a non-existent constant) --- NEWS | 2 ++ Zend/tests/bug70828.phpt | 24 ++++++++++++++++++++++++ Zend/zend_compile.c | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/bug70828.phpt diff --git a/NEWS b/NEWS index f02b240831..1ea9e3055c 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ PHP NEWS ?? ??? 2015, PHP 5.6.16 - Core: + . Fixed bug #70828 (php-fpm 5.6 with opcache crashes when referencing a + non-existent constant). (Laruence) . Fixed bug #70748 (Segfault in ini_lex () at Zend/zend_ini_scanner.l). (Laruence) diff --git a/Zend/tests/bug70828.phpt b/Zend/tests/bug70828.phpt new file mode 100644 index 0000000000..dd285b56ac --- /dev/null +++ b/Zend/tests/bug70828.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #70828 (php-fpm 5.6 with opcache crashes when referencing a non-existent constant) +--FILE-- + +--EXPECTF-- +Notice: Use of undefined constant nonexistent - assumed 'nonexistent' in /home/huixinchen/opensource/php-5.6/Zend/tests/bug70828.php on line 8 +string(11) "nonexistent" diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5ff1b042c2..fca4e2a04d 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5804,7 +5804,7 @@ void zend_do_fetch_constant(znode *result, znode *constant_container, znode *con opline->op2.constant = zend_add_const_name_literal(CG(active_op_array), &constant_name->u.constant, 0 TSRMLS_CC); } else { opline->extended_value = IS_CONSTANT_UNQUALIFIED; - if (CG(current_namespace)) { + if (check_namespace && CG(current_namespace)) { opline->extended_value |= IS_CONSTANT_IN_NAMESPACE; opline->op2.constant = zend_add_const_name_literal(CG(active_op_array), &constant_name->u.constant, 1 TSRMLS_CC); } else { From 227c898cd9b763adc5c8371b02a82e5f8351fc5f Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 2 Nov 2015 10:58:55 +0800 Subject: [PATCH 08/65] Fixed test --- Zend/tests/bug70828.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/tests/bug70828.phpt b/Zend/tests/bug70828.phpt index dd285b56ac..76111c8944 100644 --- a/Zend/tests/bug70828.phpt +++ b/Zend/tests/bug70828.phpt @@ -20,5 +20,5 @@ namespace { } ?> --EXPECTF-- -Notice: Use of undefined constant nonexistent - assumed 'nonexistent' in /home/huixinchen/opensource/php-5.6/Zend/tests/bug70828.php on line 8 +Notice: Use of undefined constant nonexistent - assumed 'nonexistent' in %sbug70828.php on line %d string(11) "nonexistent" From 8dd5e1c2b526b1460228fcdfa624cd18887da111 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 2 Nov 2015 16:35:54 +0800 Subject: [PATCH 09/65] Add test_fpm_conf to skip some tests ranth than mark --xfail-- --- sapi/fpm/tests/021-uds-acl.phpt | 11 +++++++++-- sapi/fpm/tests/include.inc | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sapi/fpm/tests/021-uds-acl.phpt b/sapi/fpm/tests/021-uds-acl.phpt index f39c526418..f5da086702 100644 --- a/sapi/fpm/tests/021-uds-acl.phpt +++ b/sapi/fpm/tests/021-uds-acl.phpt @@ -4,9 +4,16 @@ FPM: Test Unix Domain Socket with Posix ACL ---XFAIL-- -Mark as XFAIL because --with-fpm-acl is not enabled in default build --FILE-- &1', $output, $code); + if ($code) { + $msg = preg_replace("/\[.+?\]/", "", $output[0]); + return false; + } + return true; +} +/* }}} */ + function run_fpm_till($needle, $config, $max = 10) /* {{{ */ { $i = 0; @@ -76,7 +88,7 @@ function run_fpm_till($needle, $config, $max = 10) /* {{{ */ } /* }}} */ -function fpm_display_log($tail, $n=1, $ignore='systemd') { +function fpm_display_log($tail, $n=1, $ignore='systemd') { /* {{{ */ while ($n) { $a = fgets($tail); if (empty($ignore) || !strpos($a, $ignore)) { @@ -84,9 +96,9 @@ function fpm_display_log($tail, $n=1, $ignore='systemd') { $n--; } } -} +} /* }}} */ -function run_request($host, $port, $uri='/ping', $query='') { +function run_request($host, $port, $uri='/ping', $query='') { /* {{{ */ require_once 'fcgi.inc'; $client = new Adoy\FastCGI\Client($host, $port); $params = array( @@ -109,3 +121,4 @@ function run_request($host, $port, $uri='/ping', $query='') { ); return $client->request($params, false)."\n"; } +/* }}} */ From d7ff107654acb5dc682773bb0b369a7e593056d8 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 2 Nov 2015 16:43:28 +0800 Subject: [PATCH 10/65] Fixed bug #70540 (sapi/fpm/tests/008.phpt and 016.phpt should be skipped on some platforms) --- sapi/fpm/tests/008.phpt | 17 ++++++++++++++++- sapi/fpm/tests/016.phpt | 19 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/sapi/fpm/tests/008.phpt b/sapi/fpm/tests/008.phpt index 60f1ea6ebd..732a717aad 100644 --- a/sapi/fpm/tests/008.phpt +++ b/sapi/fpm/tests/008.phpt @@ -1,7 +1,22 @@ --TEST-- FPM: Test multi pool (dynamic + ondemand + static) (bug #68423) --SKIPIF-- - + --FILE-- + --FILE-- \ No newline at end of file +?> From f2ad7e73bd380be502cda0dad4d184adc25f58a3 Mon Sep 17 00:00:00 2001 From: Caleb Champlin Date: Mon, 2 Nov 2015 21:58:04 +0000 Subject: [PATCH 11/65] Make sure context is set to null to prevent use after free --- main/streams/streams.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main/streams/streams.c b/main/streams/streams.c index 3ad44b07a9..d0f8a44b98 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -84,6 +84,7 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream); if (stream->ctx) { zend_list_delete(stream->ctx); + stream->ctx = NULL; } return 0; From 2f2653aa7758cd586f1daff288146740dd5fa61b Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 3 Nov 2015 17:53:56 -0800 Subject: [PATCH 12/65] Fixed bug #70805 (Segmentation faults whilst running Drupal 8 test suite) --- NEWS | 4 ++ Zend/tests/bug70805.phpt | 46 +++++++++++++++++++ Zend/tests/bug70805_1.phpt | 43 ++++++++++++++++++ Zend/tests/bug70805_2.phpt | 37 ++++++++++++++++ Zend/zend_gc.c | 7 +++ Zend/zend_hash.c | 8 +++- Zend/zend_vm_def.h | 10 ++++- Zend/zend_vm_execute.h | 90 ++++++++++++++++++++++++++++++-------- 8 files changed, 223 insertions(+), 22 deletions(-) create mode 100644 Zend/tests/bug70805.phpt create mode 100644 Zend/tests/bug70805_1.phpt create mode 100644 Zend/tests/bug70805_2.phpt diff --git a/NEWS b/NEWS index d3f01376ce..3a0b71286b 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2015, PHP 7.0.1 +- Core: + . Fixed bug #70805 (Segmentation faults whilst running Drupal 8 test suite). + (Dmitry, Laruence) + - Opcache: . Fixed bug #70656 (require() statement broken after opcache_reset() or a few hours of use). (Laruence) diff --git a/Zend/tests/bug70805.phpt b/Zend/tests/bug70805.phpt new file mode 100644 index 0000000000..256f52eed5 --- /dev/null +++ b/Zend/tests/bug70805.phpt @@ -0,0 +1,46 @@ +--TEST-- +Bug #70805 (Segmentation faults whilst running Drupal 8 test suite) +--FILE-- +b = new B; +$a->b->a = $a; + +$i = 0; + +$c = new A; +$array = array($c); //This is used to leave a room for $GLOBALS["a"] +unset($c); + +while ($i++ < 9997) { + $t = []; + $t[] = &$t; + unset($t); +} +$t = [new C]; +$t[] = &$t; +unset($t); // This is used to trigger C::__destruct while doing gc_colloct_roots + +$e = $a; +unset($a); // This one can not be putted into roots buf because it's full, thus gc_colloct_roots will be called, + // but C::__destructor which is called in gc_colloct_roots will put $a into buf + // which will make $a be putted into gc roots buf twice +var_dump(gc_collect_cycles()); +?> +--EXPECT-- +int(0) diff --git a/Zend/tests/bug70805_1.phpt b/Zend/tests/bug70805_1.phpt new file mode 100644 index 0000000000..0225b4ce82 --- /dev/null +++ b/Zend/tests/bug70805_1.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #70805 (Segmentation faults whilst running Drupal 8 test suite) (Crash) +--FILE-- +b = new B; +$a->b->a = $a; + +$i = 0; + +$c = new A; +$array = array($c); +unset($c); + +while ($i++ < 9997) { + $t = []; + $t[] = &$t; + unset($t); +} +$t = [new C]; +$t[] = &$t; +unset($t); +unset($a); + +var_dump(gc_collect_cycles()); +?> +--EXPECT-- +int(2) diff --git a/Zend/tests/bug70805_2.phpt b/Zend/tests/bug70805_2.phpt new file mode 100644 index 0000000000..a9b11684f5 --- /dev/null +++ b/Zend/tests/bug70805_2.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #70805 (Segmentation faults whilst running Drupal 8 test suite) (Memleak) +--FILE-- +b = new B; +$a->b->a = $a; + +$i = 0; + +while ($i++ < 9998) { + $t = []; + $t[] = &$t; + unset($t); +} +$t = [new C]; +$t[] = &$t; +unset($t); + +unset($a); +var_dump(gc_collect_cycles()); +--EXPECT-- +int(2) diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c index e223a49906..74c534844d 100644 --- a/Zend/zend_gc.c +++ b/Zend/zend_gc.c @@ -242,6 +242,13 @@ ZEND_API void ZEND_FASTCALL gc_possible_root(zend_refcounted *ref) GC_REFCOUNT(ref)++; gc_collect_cycles(); GC_REFCOUNT(ref)--; + if (UNEXPECTED(GC_REFCOUNT(ref)) == 0) { + zval_dtor_func_for_ptr(ref); + return; + } + if (UNEXPECTED(GC_INFO(ref))) { + return; + } newRoot = GC_G(unused); if (!newRoot) { #if ZEND_GC_DEBUG diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 8a8ef2948e..52868cf4a6 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -1049,9 +1049,13 @@ ZEND_API int ZEND_FASTCALL zend_hash_del_ind(HashTable *ht, zend_string *key) return FAILURE; } else { if (ht->pDestructor) { - ht->pDestructor(data); + zval tmp; + ZVAL_COPY_VALUE(&tmp, data); + ZVAL_UNDEF(data); + ht->pDestructor(&tmp); + } else { + ZVAL_UNDEF(data); } - ZVAL_UNDEF(data); } } else { _zend_hash_del_el_ex(ht, idx, p, prev); diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index ad6dc58ec9..1fc343b5cb 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5513,8 +5513,14 @@ ZEND_VM_HANDLER(74, ZEND_UNSET_VAR, CONST|TMPVAR|CV, UNUSED|CONST|VAR) ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 97e08b75f9..dcf0f071f7 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -6105,8 +6105,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_CONST_CONST_HAN ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); @@ -7034,8 +7040,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_CONST_VAR_HANDL ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); @@ -7894,8 +7906,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_CONST_UNUSED_HA ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); @@ -32128,8 +32146,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_CV_CONST_HANDLE ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); @@ -33412,8 +33436,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_CV_VAR_HANDLER( ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); @@ -34642,8 +34672,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_CV_UNUSED_HANDL ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); @@ -41847,8 +41883,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_TMPVAR_CONST_HA ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); @@ -42432,8 +42474,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_TMPVAR_VAR_HAND ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); @@ -42834,8 +42882,14 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_VAR_SPEC_TMPVAR_UNUSED_H ZVAL_UNDEF(var); zval_dtor_func_for_ptr(garbage); } else { - GC_ZVAL_CHECK_POSSIBLE_ROOT(var); - ZVAL_UNDEF(var); + zval *z = var; + ZVAL_DEREF(z); + if (Z_COLLECTABLE_P(z) && UNEXPECTED(!Z_GC_INFO_P(z))) { + ZVAL_UNDEF(var); + gc_possible_root(Z_COUNTED_P(z)); + } else { + ZVAL_UNDEF(var); + } } } else { ZVAL_UNDEF(var); From fe0af271c66260fedcb4b44fad85e18dd0dd0af6 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 4 Nov 2015 18:59:30 +0800 Subject: [PATCH 13/65] Fixed bug #70843 (Segmentation fault on MacOSX with opcache.file_cache_only=1) --- NEWS | 2 ++ ext/opcache/zend_file_cache.c | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 3a0b71286b..43e7cf392a 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,8 @@ PHP NEWS (Dmitry, Laruence) - Opcache: + . Fixed bug #70843 (Segmentation fault on MacOSX with + opcache.file_cache_only=1). (Laruence) . Fixed bug #70656 (require() statement broken after opcache_reset() or a few hours of use). (Laruence) diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index a2a5343deb..d1ea0a46a6 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -20,6 +20,7 @@ #include "zend_virtual_cwd.h" #include "zend_compile.h" #include "zend_vm.h" +#include "zend_interfaces.h" #include "php.h" @@ -801,10 +802,12 @@ int zend_file_cache_script_store(zend_persistent_script *script, int in_shm) static void zend_file_cache_unserialize_hash(HashTable *ht, zend_persistent_script *script, void *buf, - unserialize_callback_t func) + unserialize_callback_t func, + dtor_func_t dtor) { Bucket *p, *end; + ht->pDestructor = dtor; if (!(ht->u.flags & HASH_FLAG_INITIALIZED)) { HT_SET_DATA_ADDR(ht, &uninitialized_bucket); return; @@ -869,7 +872,8 @@ static void zend_file_cache_unserialize_zval(zval *zv, UNSERIALIZE_PTR(Z_ARR_P(zv)); ht = Z_ARR_P(zv); - zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_zval); + zend_file_cache_unserialize_hash(ht, + script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); } break; case IS_REFERENCE: @@ -904,7 +908,8 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr UNSERIALIZE_PTR(op_array->static_variables); ht = op_array->static_variables; - zend_file_cache_unserialize_hash(ht, script, buf, zend_file_cache_unserialize_zval); + zend_file_cache_unserialize_hash(ht, + script, buf, zend_file_cache_unserialize_zval, ZVAL_PTR_DTOR); } if (op_array->literals && !IS_UNSERIALIZED(op_array->literals)) { @@ -1056,7 +1061,8 @@ static void zend_file_cache_unserialize_class(zval *zv, ce = Z_PTR_P(zv); UNSERIALIZE_STR(ce->name); - zend_file_cache_unserialize_hash(&ce->function_table, script, buf, zend_file_cache_unserialize_func); + zend_file_cache_unserialize_hash(&ce->function_table, + script, buf, zend_file_cache_unserialize_func, ZEND_FUNCTION_DTOR); if (ce->default_properties_table) { zval *p, *end; @@ -1079,10 +1085,12 @@ static void zend_file_cache_unserialize_class(zval *zv, p++; } } - zend_file_cache_unserialize_hash(&ce->constants_table, script, buf, zend_file_cache_unserialize_zval); + zend_file_cache_unserialize_hash(&ce->constants_table, + script, buf, zend_file_cache_unserialize_zval, NULL); UNSERIALIZE_STR(ZEND_CE_FILENAME(ce)); UNSERIALIZE_STR(ZEND_CE_DOC_COMMENT(ce)); - zend_file_cache_unserialize_hash(&ce->properties_info, script, buf, zend_file_cache_unserialize_prop_info); + zend_file_cache_unserialize_hash(&ce->properties_info, + script, buf, zend_file_cache_unserialize_prop_info, ZVAL_PTR_DTOR); if (ce->trait_aliases) { zend_trait_alias **p, *q; @@ -1168,6 +1176,11 @@ static void zend_file_cache_unserialize_class(zval *zv, UNSERIALIZE_PTR(ce->__tostring); UNSERIALIZE_PTR(ce->__callstatic); UNSERIALIZE_PTR(ce->__debugInfo); + + if (UNEXPECTED((ce->ce_flags & ZEND_ACC_ANON_CLASS))) { + ce->serialize = zend_class_serialize_deny; + ce->unserialize = zend_class_unserialize_deny; + } } static void zend_file_cache_unserialize(zend_persistent_script *script, @@ -1177,8 +1190,10 @@ static void zend_file_cache_unserialize(zend_persistent_script *script, UNSERIALIZE_STR(script->full_path); - zend_file_cache_unserialize_hash(&script->class_table, script, buf, zend_file_cache_unserialize_class); - zend_file_cache_unserialize_hash(&script->function_table, script, buf, zend_file_cache_unserialize_func); + zend_file_cache_unserialize_hash(&script->class_table, + script, buf, zend_file_cache_unserialize_class, ZEND_CLASS_DTOR); + zend_file_cache_unserialize_hash(&script->function_table, + script, buf, zend_file_cache_unserialize_func, ZEND_FUNCTION_DTOR); zend_file_cache_unserialize_op_array(&script->main_op_array, script, buf); UNSERIALIZE_PTR(script->arena_mem); From e4ac4e75b5dbc39ed52ff998cb4f2053541ed2d8 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 4 Nov 2015 06:44:29 -0800 Subject: [PATCH 14/65] Fixed bug #70853 (SplFixedArray throws exception when using ref variable as index) --- NEWS | 4 ++++ ext/spl/spl_engine.c | 4 ++++ ext/spl/tests/bug70853.phpt | 15 +++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 ext/spl/tests/bug70853.phpt diff --git a/NEWS b/NEWS index 43e7cf392a..30fc9bcff4 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ PHP NEWS . Fixed bug #70656 (require() statement broken after opcache_reset() or a few hours of use). (Laruence) +- SPL: + . Fixed bug #70853 (SplFixedArray throws exception when using ref variable + as index). (Laruence) + - Standard: . Fixed bug #70808 (array_merge_recursive corrupts memory of unset items). (Laruence) diff --git a/ext/spl/spl_engine.c b/ext/spl/spl_engine.c index c9960d69ef..b3d1a3e9f5 100644 --- a/ext/spl/spl_engine.c +++ b/ext/spl/spl_engine.c @@ -42,6 +42,7 @@ PHPAPI zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */ { zend_ulong idx; +try_again: switch (Z_TYPE_P(offset)) { case IS_STRING: if (ZEND_HANDLE_NUMERIC(Z_STR_P(offset), idx)) { @@ -56,6 +57,9 @@ PHPAPI zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */ return 0; case IS_TRUE: return 1; + case IS_REFERENCE: + offset = Z_REFVAL_P(offset); + goto try_again; case IS_RESOURCE: return Z_RES_HANDLE_P(offset); } diff --git a/ext/spl/tests/bug70853.phpt b/ext/spl/tests/bug70853.phpt new file mode 100644 index 0000000000..99530ece40 --- /dev/null +++ b/ext/spl/tests/bug70853.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #70853 (SplFixedArray throws exception when using ref variable as index) +--FILE-- + +--EXPECT-- +ok From 51218b3b9dc612b2db7511f93296f975b6c2aa9d Mon Sep 17 00:00:00 2001 From: Reeze Xia Date: Thu, 5 Nov 2015 13:46:03 +0800 Subject: [PATCH 15/65] Fixed bug #70852 Segfault getting NULL offset of an ArrayObject. --- NEWS | 4 ++++ ext/spl/spl_array.c | 4 ++-- ext/spl/tests/bug70852.phpt | 11 +++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 ext/spl/tests/bug70852.phpt diff --git a/NEWS b/NEWS index 1ea9e3055c..5dcb3310bc 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ PHP NEWS . Fixed bug #69757 (Segmentation fault on nextRowset). (miracle at rpz dot name) +- SPL: + . Fixed bug #70852 Segfault getting NULL offset of an ArrayObject. + (Reeze Xia) + 29 Oct 2015, PHP 5.6.15 - Core: diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 6ebbb7c068..f977aa3244 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -325,13 +325,13 @@ string_offest: if (zend_symtable_find(ht, key, len, (void **) &retval) == FAILURE) { switch (type) { case BP_VAR_R: - zend_error(E_NOTICE, "Undefined index: %s", Z_STRVAL_P(offset)); + zend_error(E_NOTICE, "Undefined index: %s", key); case BP_VAR_UNSET: case BP_VAR_IS: retval = &EG(uninitialized_zval_ptr); break; case BP_VAR_RW: - zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); + zend_error(E_NOTICE,"Undefined index: %s", key); case BP_VAR_W: { zval *value; ALLOC_INIT_ZVAL(value); diff --git a/ext/spl/tests/bug70852.phpt b/ext/spl/tests/bug70852.phpt new file mode 100644 index 0000000000..da7c00bb66 --- /dev/null +++ b/ext/spl/tests/bug70852.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #70852 Segfault getting NULL offset of an ArrayObject +--FILE-- + +===DONE=== +--EXPECTF-- +Notice: Undefined index: in %s on line %d +===DONE=== From 1c0622a472cb88f780733456f5bb0eb03a40a1cb Mon Sep 17 00:00:00 2001 From: Reeze Xia Date: Thu, 5 Nov 2015 14:09:24 +0800 Subject: [PATCH 16/65] Make test for bug #70852 to cover all cases --- ext/spl/tests/bug70852.phpt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/spl/tests/bug70852.phpt b/ext/spl/tests/bug70852.phpt index da7c00bb66..2b23ce4e09 100644 --- a/ext/spl/tests/bug70852.phpt +++ b/ext/spl/tests/bug70852.phpt @@ -3,9 +3,15 @@ Bug #70852 Segfault getting NULL offset of an ArrayObject --FILE-- ===DONE=== --EXPECTF-- Notice: Undefined index: in %s on line %d +NULL + +Notice: Undefined index: in %s on line %d +NULL ===DONE=== From dea14fc70782aa7c622a0ef5af9b163f042c05f9 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 4 Nov 2015 22:29:27 +0100 Subject: [PATCH 17/65] zero cwd buffer before passing to chmod --- Zend/zend_virtual_cwd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 4206d4d2e8..99c3f3003d 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -459,6 +459,9 @@ CWD_API void virtual_cwd_startup(void) /* {{{ */ } } #else +#ifdef ZEND_WIN32 + ZeroMemory(&cwd, sizeof(cwd)); +#endif result = getcwd(cwd, sizeof(cwd)); #endif if (!result) { From 9968129831ab0eaf92841336dc1bd6049f711d4a Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 11:58:44 +0100 Subject: [PATCH 18/65] don't get invalid chmod mode through --- Zend/zend_virtual_cwd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 99c3f3003d..fedd0a22ad 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -1566,6 +1566,20 @@ CWD_API int virtual_chmod(const char *filename, mode_t mode) /* {{{ */ return -1; } +#ifdef ZEND_WIN32 + { + mode_t _tmp = mode; + + mode = 0; + + if (_tmp & _S_IREAD) { + mode |= _S_IREAD; + } + if (_tmp & _S_IWRITE) { + mode |= _S_IWRITE; + } + } +#endif ret = chmod(new_state.cwd, mode); CWD_STATE_FREE_ERR(&new_state); From 5c96a91d77727a7af5604cd9be29a53e3afa2619 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 14:35:41 +0100 Subject: [PATCH 19/65] Fix bug #70861 Segmentation fault in pdo_parse_params() during Drupal 8 test suite --- ext/pdo/pdo_sql_parser.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c index 155ca95c1c..0907571e08 100644 --- a/ext/pdo/pdo_sql_parser.c +++ b/ext/pdo/pdo_sql_parser.c @@ -575,6 +575,10 @@ safe: zend_string *buf; buf = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); + if (!buf) { + ret = -1; + goto clean_up; + } if (!stmt->dbh->methods->quoter(stmt->dbh, ZSTR_VAL(buf), ZSTR_LEN(buf), &plc->quoted, &plc->qlen, param->param_type)) { /* bork */ From a80545992bcedca167d11689722a9bf3f7790765 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 14:45:09 +0100 Subject: [PATCH 20/65] update the actual sql parser file for #70861 --- ext/pdo/pdo_sql_parser.re | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re index 9922e03690..96c131fe96 100644 --- a/ext/pdo/pdo_sql_parser.re +++ b/ext/pdo/pdo_sql_parser.re @@ -217,6 +217,10 @@ safe: zend_string *buf; buf = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); + if (!buf) { + ret = -1; + goto clean_up; + } if (!stmt->dbh->methods->quoter(stmt->dbh, ZSTR_VAL(buf), ZSTR_LEN(buf), &plc->quoted, &plc->qlen, param->param_type)) { /* bork */ From 9385eb6ff8f85d0ab2bae96f02197fe7fc70d85c Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 14:48:30 +0100 Subject: [PATCH 21/65] re-update NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 30fc9bcff4..2e0007f0f7 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ PHP NEWS . Fixed bug #70656 (require() statement broken after opcache_reset() or a few hours of use). (Laruence) +- PDO: + . Fix bug #70861 (Segmentation fault in pdo_parse_params() during Drupal 8 + test suite). (Anatol) + - SPL: . Fixed bug #70853 (SplFixedArray throws exception when using ref variable as index). (Laruence) From 5ac288bcc6b8858e3ea509d92426b2bacc7fd397 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 18:08:08 +0100 Subject: [PATCH 22/65] fix crash in sqlite when executing with bound stream param rel #70862 --- ext/sqlite3/sqlite3.c | 9 +++-- .../tests/sqlite3_blob_bind_resource.phpt | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 ext/sqlite3/tests/sqlite3_blob_bind_resource.phpt diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 12340f991e..4e3cc28eda 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1527,7 +1527,7 @@ PHP_METHOD(sqlite3stmt, execute) case SQLITE_BLOB: { php_stream *stream = NULL; - zend_string *buffer; + zend_string *buffer = NULL; if (Z_TYPE_P(parameter) == IS_RESOURCE) { php_stream_from_zval_no_verify(stream, parameter); if (stream == NULL) { @@ -1540,10 +1540,11 @@ PHP_METHOD(sqlite3stmt, execute) buffer = Z_STR_P(parameter); } - sqlite3_bind_blob(stmt_obj->stmt, param->param_number, ZSTR_VAL(buffer), ZSTR_LEN(buffer), SQLITE_TRANSIENT); - - if (stream) { + if (buffer) { + sqlite3_bind_blob(stmt_obj->stmt, param->param_number, ZSTR_VAL(buffer), ZSTR_LEN(buffer), SQLITE_TRANSIENT); zend_string_release(buffer); + } else { + sqlite3_bind_null(stmt_obj->stmt, param->param_number); } break; } diff --git a/ext/sqlite3/tests/sqlite3_blob_bind_resource.phpt b/ext/sqlite3/tests/sqlite3_blob_bind_resource.phpt new file mode 100644 index 0000000000..108956b87b --- /dev/null +++ b/ext/sqlite3/tests/sqlite3_blob_bind_resource.phpt @@ -0,0 +1,39 @@ +--TEST-- +SQLite3::execute() with a resource bound for blob param +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE test (id STRING, data BLOB)')); +$insert_stmt = $db->prepare("INSERT INTO test (id, data) VALUES (1, ?)"); + + +class HelloWrapper { + public function stream_open() { return true; } + public function stream_eof() { return true; } + public function stream_read() { return NULL; } + public function stream_stat() { return array(); } +} +stream_wrapper_register("hello", "HelloWrapper"); + +$f = fopen("hello://there", "r"); + +var_dump($insert_stmt->bindParam(1, $f, SQLITE3_BLOB)); +var_dump($insert_stmt->execute()); + +var_dump($insert_stmt->close()); +fclose($f); + +?> ++++DONE+++ +--EXPECTF-- +bool(true) +bool(true) +object(SQLite3Result)#%d (%d) { +} +bool(true) ++++DONE+++ From f189353178bd8e88bee9590669dfd0c53b784b28 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 18:16:32 +0100 Subject: [PATCH 23/65] fix possible NULL deref in image functions --- ext/standard/image.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ext/standard/image.c b/ext/standard/image.c index 378423917e..7f100d68f9 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -217,11 +217,16 @@ static struct gfxinfo *php_handle_swc(php_stream * stream) if (uncompress(b, &len, a, sizeof(a)) != Z_OK) { /* failed to decompress the file, will try reading the rest of the file */ - if (php_stream_seek(stream, 8, SEEK_SET)) + if (php_stream_seek(stream, 8, SEEK_SET)) { return NULL; + } bufz = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); + if (!bufz) { + return NULL; + } + /* * zlib::uncompress() wants to know the output data length * if none was given as a parameter From 1fcadf67e652622577ab0467e40c812e132ec9f3 Mon Sep 17 00:00:00 2001 From: Fabian Franz Date: Thu, 5 Nov 2015 18:21:45 +0000 Subject: [PATCH 24/65] Fix setting of empty string resource. --- ext/pdo/pdo_sql_parser.c | 3 +-- ext/pdo/pdo_sql_parser.re | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c index 0907571e08..22e5fcf35b 100644 --- a/ext/pdo/pdo_sql_parser.c +++ b/ext/pdo/pdo_sql_parser.c @@ -576,8 +576,7 @@ safe: buf = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); if (!buf) { - ret = -1; - goto clean_up; + buf = ZSTR_EMPTY_ALLOC(); } if (!stmt->dbh->methods->quoter(stmt->dbh, ZSTR_VAL(buf), ZSTR_LEN(buf), &plc->quoted, &plc->qlen, param->param_type)) { diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re index 96c131fe96..629f3079c2 100644 --- a/ext/pdo/pdo_sql_parser.re +++ b/ext/pdo/pdo_sql_parser.re @@ -218,8 +218,7 @@ safe: buf = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); if (!buf) { - ret = -1; - goto clean_up; + buf = ZSTR_EMPTY_ALLOC(); } if (!stmt->dbh->methods->quoter(stmt->dbh, ZSTR_VAL(buf), ZSTR_LEN(buf), &plc->quoted, &plc->qlen, param->param_type)) { From 1184f0aca5a4fafc893f131f6012dc44cf5846c4 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 19:48:08 +0100 Subject: [PATCH 25/65] add test for bug #70861 --- ext/pdo_pgsql/tests/bug70861.phpt | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ext/pdo_pgsql/tests/bug70861.phpt diff --git a/ext/pdo_pgsql/tests/bug70861.phpt b/ext/pdo_pgsql/tests/bug70861.phpt new file mode 100644 index 0000000000..7edebba1e6 --- /dev/null +++ b/ext/pdo_pgsql/tests/bug70861.phpt @@ -0,0 +1,46 @@ +--TEST-- +Bug #70861 Segmentation fault in pdo_parse_params() during Drupal 8 test suite +--SKIPIF-- + +--FILE-- +setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + +try { + @$db->query("SET bytea_output = 'escape'"); +} catch (Exception $e) { +} + +$db->query('DROP TABLE IF EXISTS test_blob_crash CASCADE'); +$db->query('CREATE TABLE test_blob_crash (id SERIAL NOT NULL, blob1 BYTEA)'); + +class HelloWrapper { + public function stream_open() { return true; } + public function stream_eof() { return true; } + public function stream_read() { return NULL; } + public function stream_stat() { return array(); } +} +stream_wrapper_register("hello", "HelloWrapper"); + +$f = fopen("hello://there", "r"); + +$stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); + +$stmt->bindparam(':foo', $f, PDO::PARAM_LOB); +$stmt->execute(); + +fclose($f); + +?> ++++DONE+++ +--EXPECTF-- +%a ++++DONE+++ From 7b32b8f4e142dab17d67721f990ec06749db6768 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 21:32:31 +0100 Subject: [PATCH 26/65] fix pdo_mysql crash with empty bound stream param rel #70862 --- ext/pdo_mysql/mysql_statement.c | 5 ++-- ext/pdo_mysql/tests/bug70862.phpt | 46 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 ext/pdo_mysql/tests/bug70862.phpt diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index f55843072f..7c6d3272fd 100644 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -523,10 +523,11 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da parameter = Z_REFVAL(param->parameter); } if (Z_TYPE_P(parameter) == IS_RESOURCE) { - php_stream *stm; + php_stream *stm = NULL; php_stream_from_zval_no_verify(stm, parameter); if (stm) { - ZVAL_STR(parameter, php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0)); + zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); + ZVAL_STR(parameter, mem ? mem : STR_EMPTY_ALLOC()); } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource"); return 0; diff --git a/ext/pdo_mysql/tests/bug70862.phpt b/ext/pdo_mysql/tests/bug70862.phpt new file mode 100644 index 0000000000..4a3a618854 --- /dev/null +++ b/ext/pdo_mysql/tests/bug70862.phpt @@ -0,0 +1,46 @@ +--TEST-- +MySQL Prepared Statements and BLOBs +--SKIPIF-- + +--FILE-- +exec('DROP TABLE IF EXISTS test'); + $db->exec(sprintf('CREATE TABLE test(id INT, label BLOB)')); + + $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); + $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + + class HelloWrapper { + public function stream_open() { return true; } + public function stream_eof() { return true; } + public function stream_read() { return NULL; } + public function stream_stat() { return array(); } + } + stream_wrapper_register("hello", "HelloWrapper"); + + $f = fopen("hello://there", "r"); + + $stmt = $db->prepare('INSERT INTO test(id, label) VALUES (1, :para)'); + $stmt->bindParam(":para", $f, PDO::PARAM_LOB); + $stmt->execute(); + + var_dump($f); + + print "done!"; +?> +--CLEAN-- +exec('DROP TABLE IF EXISTS test'); +?> +--EXPECTF-- +string(0) "" +done! From 1406f80135e87532269a50cd143cfdd911a1368a Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 21:49:21 +0100 Subject: [PATCH 27/65] fix leak --- ext/pdo_mysql/mysql_statement.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index 7c6d3272fd..ac94632aae 100644 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -527,6 +527,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da php_stream_from_zval_no_verify(stm, parameter); if (stm) { zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); + zval_ptr_dtor(parameter); ZVAL_STR(parameter, mem ? mem : STR_EMPTY_ALLOC()); } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource"); From cff9e16a124f84e8c03a7a4315c8e052db530d0c Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 21:50:34 +0100 Subject: [PATCH 28/65] fix pdo_sqlite crash with empty bound stream --- ext/pdo_sqlite/sqlite_statement.c | 5 +++-- ext/pdo_sqlite/tests/bug70862.phpt | 36 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 ext/pdo_sqlite/tests/bug70862.phpt diff --git a/ext/pdo_sqlite/sqlite_statement.c b/ext/pdo_sqlite/sqlite_statement.c index 9b74b24212..93807c834c 100644 --- a/ext/pdo_sqlite/sqlite_statement.c +++ b/ext/pdo_sqlite/sqlite_statement.c @@ -138,11 +138,12 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d parameter = ¶m->parameter; } if (Z_TYPE_P(parameter) == IS_RESOURCE) { - php_stream *stm; + php_stream *stm = NULL; php_stream_from_zval_no_verify(stm, parameter); if (stm) { + zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor(parameter); - ZVAL_STR(parameter, php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0)); + ZVAL_STR(parameter, mem ? mem : STR_EMPTY_ALLOC()); } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource"); return 0; diff --git a/ext/pdo_sqlite/tests/bug70862.phpt b/ext/pdo_sqlite/tests/bug70862.phpt new file mode 100644 index 0000000000..3df1e4f2bd --- /dev/null +++ b/ext/pdo_sqlite/tests/bug70862.phpt @@ -0,0 +1,36 @@ +--TEST-- +PDO_sqlite: Testing sqliteCreateCollation() +--SKIPIF-- + +--FILE-- +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +$db->exec('CREATE TABLE test(field BLOB)'); + +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); + +class HelloWrapper { + public function stream_open() { return true; } + public function stream_eof() { return true; } + public function stream_read() { return NULL; } + public function stream_stat() { return array(); } +} +stream_wrapper_register("hello", "HelloWrapper"); + +$f = fopen("hello://there", "r"); + +$stmt = $db->prepare('INSERT INTO test(field) VALUES (:para)'); +$stmt->bindParam(":para", $f, PDO::PARAM_LOB); +$stmt->execute(); + +var_dump($f); + +?> ++++DONE+++ +--EXPECTF-- +string(0) "" ++++DONE+++ From c1f893d894d00092aa839e236671a89948f5e431 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 22:11:00 +0100 Subject: [PATCH 29/65] fix NULL deref in pdo_firebird ref #70862 --- ext/pdo_firebird/firebird_statement.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index 1e0151dc9d..5eaf530415 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -523,12 +523,13 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat } if (Z_TYPE_P(parameter) == IS_RESOURCE) { - php_stream *stm; + php_stream *stm = NULL; php_stream_from_zval_no_verify(stm, parameter); if (stm) { + zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor(parameter); - ZVAL_STR(parameter, php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0)); + ZVAL_STR(parameter, mem ? mem : STR_EMPTY_ALLOC()); } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource"); return 0; From 2283551cfa8f6720d13ad396e8f3da1bc4f52389 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 22:24:47 +0100 Subject: [PATCH 30/65] fix NULL deref in mbstring post handler --- ext/mbstring/mb_gpc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/mbstring/mb_gpc.c b/ext/mbstring/mb_gpc.c index db6b5c47cd..0607894447 100644 --- a/ext/mbstring/mb_gpc.c +++ b/ext/mbstring/mb_gpc.c @@ -377,8 +377,10 @@ SAPI_POST_HANDLER_FUNC(php_mb_post_handler) php_stream_rewind(SG(request_info).request_body); post_data_str = php_stream_copy_to_mem(SG(request_info).request_body, PHP_STREAM_COPY_ALL, 0); - detected = _php_mb_encoding_handler_ex(&info, arg, ZSTR_VAL(post_data_str)); - zend_string_release(post_data_str); + detected = _php_mb_encoding_handler_ex(&info, arg, post_data_str ? ZSTR_VAL(post_data_str) : NULL); + if (post_data_str) { + zend_string_release(post_data_str); + } MBSTRG(http_input_identify) = detected; if (detected) { From 01c844a01dc6e4e819f0568682cd1b71a4dcb0ff Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 22:39:10 +0100 Subject: [PATCH 31/65] use Z* macro name --- ext/pdo_firebird/firebird_statement.c | 2 +- ext/pdo_mysql/mysql_statement.c | 2 +- ext/pdo_sqlite/sqlite_statement.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index 5eaf530415..5445368bc9 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -529,7 +529,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat if (stm) { zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor(parameter); - ZVAL_STR(parameter, mem ? mem : STR_EMPTY_ALLOC()); + ZVAL_STR(parameter, mem ? mem : ZSTR_EMPTY_ALLOC()); } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource"); return 0; diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index ac94632aae..2c7e39bbbd 100644 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -528,7 +528,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da if (stm) { zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor(parameter); - ZVAL_STR(parameter, mem ? mem : STR_EMPTY_ALLOC()); + ZVAL_STR(parameter, mem ? mem : ZSTR_EMPTY_ALLOC()); } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource"); return 0; diff --git a/ext/pdo_sqlite/sqlite_statement.c b/ext/pdo_sqlite/sqlite_statement.c index 93807c834c..efe84c11cd 100644 --- a/ext/pdo_sqlite/sqlite_statement.c +++ b/ext/pdo_sqlite/sqlite_statement.c @@ -143,7 +143,7 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d if (stm) { zend_string *mem = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); zval_ptr_dtor(parameter); - ZVAL_STR(parameter, mem ? mem : STR_EMPTY_ALLOC()); + ZVAL_STR(parameter, mem ? mem : ZSTR_EMPTY_ALLOC()); } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource"); return 0; From aa0d441ede5218d4f9b9f161e37783a5fd9d3b9f Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Nov 2015 22:51:25 +0100 Subject: [PATCH 32/65] update NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 2e0007f0f7..b19123201a 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - Core: . Fixed bug #70805 (Segmentation faults whilst running Drupal 8 test suite). (Dmitry, Laruence) + . Fixed bug #70862 (Several functions do not check return code of + php_stream_copy_to_mem()). (Anatol) - Opcache: . Fixed bug #70843 (Segmentation fault on MacOSX with From 283b6275df22a2e94a723a135291014b17317630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Almada?= Date: Thu, 5 Nov 2015 22:20:49 -0300 Subject: [PATCH 33/65] add failing test for bug #70868 --- Zend/tests/bug70868.phpt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Zend/tests/bug70868.phpt diff --git a/Zend/tests/bug70868.phpt b/Zend/tests/bug70868.phpt new file mode 100644 index 0000000000..d3dd76354a --- /dev/null +++ b/Zend/tests/bug70868.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #70868, with PCRE JIT +--INI-- +pcre.jit=1 +--SKIPIF-- + +--FILE-- + +--EXPECTF-- + +string(6) "A.phpt" +string(6) "B.phpt" +string(6) "C.phpt" +Done From 27aef97f658dd956db0cf4145963d9d57d31dacc Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 6 Nov 2015 11:37:17 +0800 Subject: [PATCH 34/65] Fixed bug #70868 (PCRE JIT and pattern reuse segfault) --- NEWS | 1 + ext/spl/spl_iterators.c | 5 +++++ {Zend => ext/spl}/tests/bug70868.phpt | 0 3 files changed, 6 insertions(+) rename {Zend => ext/spl}/tests/bug70868.phpt (100%) diff --git a/NEWS b/NEWS index b19123201a..0985ae6dda 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ PHP NEWS test suite). (Anatol) - SPL: + . Fixed bug #70868 (PCRE JIT and pattern reuse segfault). (Laruence) . Fixed bug #70853 (SplFixedArray throws exception when using ref variable as index). (Laruence) diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index cd0c624b50..b29fc5298b 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -2059,6 +2059,11 @@ SPL_METHOD(RegexIterator, accept) { case REGIT_MODE_MAX: /* won't happen but makes compiler happy */ case REGIT_MODE_MATCH: +#ifdef PCRE_EXTRA_MARK + if (intern->u.regex.pce->extra) { + intern->u.regex.pce->extra->flags &= ~PCRE_EXTRA_MARK; + } +#endif count = pcre_exec(intern->u.regex.pce->re, intern->u.regex.pce->extra, ZSTR_VAL(subject), ZSTR_LEN(subject), 0, 0, NULL, 0); RETVAL_BOOL(count >= 0); break; diff --git a/Zend/tests/bug70868.phpt b/ext/spl/tests/bug70868.phpt similarity index 100% rename from Zend/tests/bug70868.phpt rename to ext/spl/tests/bug70868.phpt From 3060dfd92e0126e92b1501dba807bfcd44bef53a Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Sat, 7 Nov 2015 01:56:50 +1100 Subject: [PATCH 35/65] Fix bug 68298 (PHP OCI8 OCI int overflow) (Senthil) --- ext/oci8/oci8_statement.c | 9 ++++++- ext/oci8/tests/bug68298.phpt | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 ext/oci8/tests/bug68298.phpt diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index 4d18a916d8..ad30a65377 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -1139,15 +1139,22 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, case SQLT_INT: case SQLT_NUM: + { if (Z_TYPE_P(var) == IS_RESOURCE || Z_TYPE_P(var) == IS_OBJECT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); return 1; } convert_to_long(var); +#if defined(OCI_MAJOR_VERSION) && OCI_MAJOR_VERSION > 10 + bind_data = (ub8 *)&Z_LVAL_P(var); + value_sz = sizeof(ub8); +#else bind_data = (ub4 *)&Z_LVAL_P(var); value_sz = sizeof(ub4); +#endif mode = OCI_DEFAULT; - break; + } + break; case SQLT_LBI: case SQLT_BIN: diff --git a/ext/oci8/tests/bug68298.phpt b/ext/oci8/tests/bug68298.phpt new file mode 100644 index 0000000000..223faa5cad --- /dev/null +++ b/ext/oci8/tests/bug68298.phpt @@ -0,0 +1,51 @@ +--TEST-- +Bug #68298 (OCI int overflow) +--SKIPIF-- + +--FILE-- + +===DONE=== + +--EXPECTF-- +array(1) { + ["COL1"]=> + array(2) { + [0]=> + string(19) "1152921504606846975" + [1]=> + string(20) "-1152921504606846975" + } +} +===DONE=== From f88a9a964368ad21e78cf96197952aa3e03d4604 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Sat, 7 Nov 2015 02:10:57 +1100 Subject: [PATCH 36/65] Bump OCI8 version --- ext/oci8/package.xml | 132 ++++++++++++++++++++++++------------------- ext/oci8/php_oci8.h | 2 +- 2 files changed, 75 insertions(+), 59 deletions(-) diff --git a/ext/oci8/package.xml b/ext/oci8/package.xml index e5839f1399..58d3f70b75 100644 --- a/ext/oci8/package.xml +++ b/ext/oci8/package.xml @@ -45,12 +45,12 @@ libraries are available. no - 2014-03-19 + 2015-11-06 - 2.0.9 - 2.0.9 + 2.0.10 + 2.0.10 stable @@ -58,7 +58,7 @@ libraries are available. PHP -Fixed oci_field_* reflection: $field can be a column name or index +Fixed bug #68298 (OCI int overflow) @@ -79,36 +79,36 @@ Fixed oci_field_* reflection: $field can be a column name or index - - + - + - + + - - + - + - + + - + - + @@ -119,13 +119,13 @@ Fixed oci_field_* reflection: $field can be a column name or index - - + + - + @@ -143,8 +143,8 @@ Fixed oci_field_* reflection: $field can be a column name or index - + @@ -157,54 +157,55 @@ Fixed oci_field_* reflection: $field can be a column name or index + - - + - + + - + - - + - + - + - + - + - + - + - + + + - - - - + + + @@ -214,24 +215,25 @@ Fixed oci_field_* reflection: $field can be a column name or index - - - + + + - - + - + + + - + @@ -240,7 +242,6 @@ Fixed oci_field_* reflection: $field can be a column name or index - @@ -265,6 +266,7 @@ Fixed oci_field_* reflection: $field can be a column name or index + @@ -273,7 +275,6 @@ Fixed oci_field_* reflection: $field can be a column name or index - @@ -281,28 +282,28 @@ Fixed oci_field_* reflection: $field can be a column name or index + + - + - + - - + - @@ -383,33 +384,33 @@ Fixed oci_field_* reflection: $field can be a column name or index + - - + + - - - + + - - + + @@ -420,11 +421,11 @@ Fixed oci_field_* reflection: $field can be a column name or index - + - + @@ -461,6 +462,21 @@ Fixed oci_field_* reflection: $field can be a column name or index + + + 2.0.9 + 2.0.9 + + + stable + stable + + PHP + +Fixed oci_field_* reflection: $field can be a column name or index + + + 2.0.8 diff --git a/ext/oci8/php_oci8.h b/ext/oci8/php_oci8.h index deb23c283a..10ee3d4cb7 100644 --- a/ext/oci8/php_oci8.h +++ b/ext/oci8/php_oci8.h @@ -45,7 +45,7 @@ */ #undef PHP_OCI8_VERSION #endif -#define PHP_OCI8_VERSION "2.0.9" +#define PHP_OCI8_VERSION "2.0.10" extern zend_module_entry oci8_module_entry; #define phpext_oci8_ptr &oci8_module_entry From a57b2053832fc0136d6b894148d0d20c0d9d90df Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Sat, 7 Nov 2015 02:14:18 +1100 Subject: [PATCH 37/65] Fix compile warnings about comparison of unsigned expression always being true --- ext/oci8/oci8_interface.c | 2 +- ext/oci8/oci8_lob.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index bb7212290d..817b8dbf8b 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -373,7 +373,7 @@ PHP_FUNCTION(oci_lob_eof) PHP_OCI_ZVAL_TO_DESCRIPTOR(*tmp, descriptor); - if (!php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC) && lob_length >= 0) { + if (!php_oci_lob_get_length(descriptor, &lob_length TSRMLS_CC)) { if (lob_length == descriptor->lob_current_position) { RETURN_TRUE; } diff --git a/ext/oci8/oci8_lob.c b/ext/oci8/oci8_lob.c index ca08373ff2..079e0a6a8f 100644 --- a/ext/oci8/oci8_lob.c +++ b/ext/oci8/oci8_lob.c @@ -417,10 +417,6 @@ int php_oci_lob_write (php_oci_descriptor *descriptor, ub4 offset, char *data, i return 0; } - if (offset < 0) { - offset = 0; - } - if (offset > descriptor->lob_current_position) { offset = descriptor->lob_current_position; } From 089ca134fb79ba57cdc89a3a8d9800577bce5ddf Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Sat, 7 Nov 2015 02:15:24 +1100 Subject: [PATCH 38/65] Always remember NEWS.... --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index 5dcb3310bc..1d0ed5ea88 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,9 @@ PHP NEWS . Fixed bug #70748 (Segfault in ini_lex () at Zend/zend_ini_scanner.l). (Laruence) +- OCI8: + . Fixed bug #68298 (OCI int overflow) (Senthil). + - PDO_DBlib: . Fixed bug #69757 (Segmentation fault on nextRowset). (miracle at rpz dot name) From 049325ca9662e1d5e6fb2fdc7006b9a68385d9f9 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Sat, 7 Nov 2015 02:24:17 +1100 Subject: [PATCH 39/65] Fix bug 68298 (PHP OCI8 OCI int overflow) (Senthil) --- ext/oci8/oci8_statement.c | 5 ++++ ext/oci8/tests/bug68298.phpt | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 ext/oci8/tests/bug68298.phpt diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index a23ed2bbb1..4ec7d2964a 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -1149,8 +1149,13 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l return 1; } convert_to_long(var); +#if defined(OCI_MAJOR_VERSION) && OCI_MAJOR_VERSION > 10 + bind_data = (ub8 *)&Z_LVAL_P(var); + value_sz = sizeof(ub8); +#else bind_data = (ub4 *)&Z_LVAL_P(var); value_sz = sizeof(ub4); +#endif mode = OCI_DEFAULT; break; diff --git a/ext/oci8/tests/bug68298.phpt b/ext/oci8/tests/bug68298.phpt new file mode 100644 index 0000000000..223faa5cad --- /dev/null +++ b/ext/oci8/tests/bug68298.phpt @@ -0,0 +1,51 @@ +--TEST-- +Bug #68298 (OCI int overflow) +--SKIPIF-- + +--FILE-- + +===DONE=== + +--EXPECTF-- +array(1) { + ["COL1"]=> + array(2) { + [0]=> + string(19) "1152921504606846975" + [1]=> + string(20) "-1152921504606846975" + } +} +===DONE=== From 855bb36fd0bad9ac99a176d75a2792e9a1ed23a3 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Fri, 6 Nov 2015 21:41:51 +0100 Subject: [PATCH 40/65] Add support for IPV6_V6ONLY on sockets --- NEWS | 3 +++ ext/sockets/sockets.c | 4 ++++ main/network.c | 6 ++++++ main/php_network.h | 8 +++++--- main/streams/xp_socket.c | 10 ++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 0985ae6dda..9bac88ffc6 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,9 @@ PHP NEWS . Fixed bug #70808 (array_merge_recursive corrupts memory of unset items). (Laruence) +- Streams/Socket + . Add IPV6_V6ONLY constant / make it usable in stream contexts. (Bob) + - XSL: . Fixed bug #70678 (PHP7 returns true when false is expected). (Felipe) diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 4385093fe9..39bfd2bf49 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -716,6 +716,10 @@ static PHP_MINIT_FUNCTION(sockets) REGISTER_LONG_CONSTANT("IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP, CONST_CS | CONST_PERSISTENT); #endif +#ifdef IPV6_V6ONLY + REGISTER_LONG_CONSTANT("IPV6_V6ONLY", IPV6_V6ONLY, CONST_CS | CONST_PERSISTENT); +#endif + #ifndef WIN32 # include "unix_socket_constants.h" #else diff --git a/main/network.c b/main/network.c index c08194bcd6..cb112464d1 100644 --- a/main/network.c +++ b/main/network.c @@ -472,6 +472,12 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po #ifdef SO_REUSEADDR setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&sockoptval, sizeof(sockoptval)); #endif +#ifdef IPV6_V6ONLY + if (sockopts & STREAM_SOCKOP_IPV6_V6ONLY) { + int ipv6_val = !!(sockopts & STREAM_SOCKOP_IPV6_V6ONLY_ENABLED); + setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&ipv6_val, sizeof(sockoptval)); + } +#endif #ifdef SO_REUSEPORT if (sockopts & STREAM_SOCKOP_SO_REUSEPORT) { setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char*)&sockoptval, sizeof(sockoptval)); diff --git a/main/php_network.h b/main/php_network.h index d17530208a..a0b87797b6 100644 --- a/main/php_network.h +++ b/main/php_network.h @@ -106,9 +106,11 @@ typedef int php_socket_t; # define SOCK_RECV_ERR -1 #endif -#define STREAM_SOCKOP_NONE 1 << 0 -#define STREAM_SOCKOP_SO_REUSEPORT 1 << 1 -#define STREAM_SOCKOP_SO_BROADCAST 1 << 2 +#define STREAM_SOCKOP_NONE (1 << 0) +#define STREAM_SOCKOP_SO_REUSEPORT (1 << 1) +#define STREAM_SOCKOP_SO_BROADCAST (1 << 2) +#define STREAM_SOCKOP_IPV6_V6ONLY (1 << 3) +#define STREAM_SOCKOP_IPV6_V6ONLY_ENABLED (1 << 4) /* uncomment this to debug poll(2) emulation on systems that have poll(2) */ diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index e88bb91208..be4edd76e9 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -635,6 +635,16 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t * return -1; } +#ifdef IPV6_V6ONLY + if (PHP_STREAM_CONTEXT(stream) + && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "ipv6_v6only")) != NULL + && Z_TYPE_P(tmpzval) != IS_NULL + ) { + sockopts |= STREAM_SOCKOP_IPV6_V6ONLY; + sockopts |= STREAM_SOCKOP_IPV6_V6ONLY_ENABLED * zend_is_true(tmpzval); + } +#endif + #ifdef SO_REUSEPORT if (PHP_STREAM_CONTEXT(stream) && (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "so_reuseport")) != NULL From 6897c1116af54241e9e49a74f3cdf887ecca9d79 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 6 Nov 2015 15:31:01 +0100 Subject: [PATCH 41/65] no more dev ZEND_VERSION --- Zend/zend.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend.h b/Zend/zend.h index f1fb37c3f0..2192f5b1b2 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -22,7 +22,7 @@ #ifndef ZEND_H #define ZEND_H -#define ZEND_VERSION "3.0.0-dev" +#define ZEND_VERSION "3.0.0" #define ZEND_ENGINE_3 From 8155ecba61a9c724c7b2bdeb673602ae27923d71 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 6 Nov 2015 23:03:15 +0100 Subject: [PATCH 42/65] Fixed bug #70863 Incorect logic to increment_function for proxy objects --- Zend/zend_operators.c | 2 +- sapi/cli/tests/006.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 14dafe353b..bad2aa648f 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -2277,7 +2277,7 @@ try_again: zval *val; val = Z_OBJ_HANDLER_P(op1, get)(op1, &rv); - Z_ADDREF_P(val); + Z_TRY_ADDREF_P(val); increment_function(val); Z_OBJ_HANDLER_P(op1, set)(op1, val); zval_ptr_dtor(val); diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt index 1170ea217a..b24da56660 100644 --- a/sapi/cli/tests/006.phpt +++ b/sapi/cli/tests/006.phpt @@ -25,7 +25,7 @@ string(44) "Exception: Extension unknown does not exist " string(37) "Exception: Extension does not exist " -string(%d) "Extension [ extension #%d pcre version %d.%d.%d%a ] { +string(%d) "Extension [ extension #%d pcre version %s ] { - INI { Entry [ pcre.backtrack_limit ] From d59eb9fcc3ce981a53c004c440b67f131d56bd7e Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 6 Nov 2015 23:05:35 +0100 Subject: [PATCH 43/65] fix decrement_function regarding bug #70863 --- Zend/zend_operators.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index bad2aa648f..3f4f29020e 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -2345,7 +2345,7 @@ try_again: zval *val; val = Z_OBJ_HANDLER_P(op1, get)(op1, &rv); - Z_ADDREF_P(val); + Z_TRY_ADDREF_P(val); decrement_function(val); Z_OBJ_HANDLER_P(op1, set)(op1, val); zval_ptr_dtor(val); From 0cbf3afe172345b9abb008082fc78bae9ba07462 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 6 Nov 2015 23:08:18 +0100 Subject: [PATCH 44/65] update NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 9bac88ffc6..014d53f0cd 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,8 @@ PHP NEWS (Dmitry, Laruence) . Fixed bug #70862 (Several functions do not check return code of php_stream_copy_to_mem()). (Anatol) + . Fixed bug #70863 (Incorect logic to increment_function for proxy objects). + (Anatol) - Opcache: . Fixed bug #70843 (Segmentation fault on MacOSX with From fd61666d96277779b1b85f59a0651cb42eed3420 Mon Sep 17 00:00:00 2001 From: Matteo Beccati Date: Sat, 7 Nov 2015 10:35:45 +0100 Subject: [PATCH 45/65] Fix bug #70875 Segmentation fault if wsdl has no targetNamespace attribute --- NEWS | 4 + ext/soap/php_sdl.c | 2 +- ext/soap/tests/bug70875.phpt | 50 +++++++++++ ext/soap/tests/bug70875.wsdl | 156 +++++++++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 ext/soap/tests/bug70875.phpt create mode 100644 ext/soap/tests/bug70875.wsdl diff --git a/NEWS b/NEWS index 1d0ed5ea88..6164dd59a4 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,10 @@ PHP NEWS . Fixed bug #69757 (Segmentation fault on nextRowset). (miracle at rpz dot name) +- SOAP: + . Fixed bug #70875 (Segmentation fault if wsdl has no targetNamespace + attribute). (Matteo) + - SPL: . Fixed bug #70852 Segfault getting NULL offset of an ArrayObject. (Reeze Xia) diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 355762123c..4ba1119d35 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -111,7 +111,7 @@ encodePtr get_encoder(sdlPtr sdl, const char *ns, const char *type) { encodePtr enc = NULL; char *nscat; - int ns_len = strlen(ns); + int ns_len = ns ? strlen(ns) : 0; int type_len = strlen(type); int len = ns_len + type_len + 1; diff --git a/ext/soap/tests/bug70875.phpt b/ext/soap/tests/bug70875.phpt new file mode 100644 index 0000000000..6f10462bfc --- /dev/null +++ b/ext/soap/tests/bug70875.phpt @@ -0,0 +1,50 @@ +--TEST-- +SOAP Bug #70875 - Segmentation fault if wsdl has no targetNamespace attribute +--SKIPIF-- + +--INI-- +soap.wsdl_cache_enabled=0 +--FILE-- + 1, + 'classmap' => [ + 'TestService' => 'TestService', + 'TestServiceRQ' => 'TestServiceRQ', + 'RqHeader' => 'RqHeader', + ], +]); + + +class TestService +{ + public $TestServiceRQ; +} + +class TestServiceRQ +{ + public $RqHeader; +} + +class RqHeader +{ +} + +$r = new TestService(); +$r->TestServiceRQ = new TestServiceRQ(); +$r->TestServiceRQ->RqHeader = new RqHeader(); + +$c->testService($r); + +?> +--EXPECT-- +no SIGSEGV diff --git a/ext/soap/tests/bug70875.wsdl b/ext/soap/tests/bug70875.wsdl new file mode 100644 index 0000000000..f874b9ae6c --- /dev/null +++ b/ext/soap/tests/bug70875.wsdl @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 632bee4abbcca0f3ab6ec2b15c87fb946b6d7129 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 6 Nov 2015 23:00:39 +0100 Subject: [PATCH 46/65] Fix update_opX_const lowercasing It was lowering in-place. --- .../varSyntax/static_prop_on_expr_class.phpt | 13 +++++++++++ ext/opcache/Optimizer/zend_optimizer.c | 23 +++++++++---------- 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 Zend/tests/varSyntax/static_prop_on_expr_class.phpt diff --git a/Zend/tests/varSyntax/static_prop_on_expr_class.phpt b/Zend/tests/varSyntax/static_prop_on_expr_class.phpt new file mode 100644 index 0000000000..d17b6cdb0b --- /dev/null +++ b/Zend/tests/varSyntax/static_prop_on_expr_class.phpt @@ -0,0 +1,13 @@ +--TEST-- +Accessing a static property on a statically evaluable class expression +--FILE-- + +--EXPECT-- +int(42) diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 22bb806a4c..1f5e4f1bf6 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -110,6 +110,13 @@ int zend_optimizer_add_literal(zend_op_array *op_array, zval *zv) return i; } +static inline int zend_optimizer_add_literal_string(zend_op_array *op_array, zend_string *str) { + zval zv; + ZVAL_STR(&zv, str); + zend_string_hash_val(str); + return zend_optimizer_add_literal(op_array, &zv); +} + int zend_optimizer_is_disabled_func(const char *name, size_t len) { zend_function *fbc = (zend_function *)zend_hash_str_find_ptr(EG(function_table), name, len); @@ -137,9 +144,7 @@ void zend_optimizer_update_op1_const(zend_op_array *op_array, zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->cache_size; op_array->cache_size += sizeof(void*); - zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); - zend_optimizer_add_literal(op_array, val); - zend_string_hash_val(Z_STR(op_array->literals[opline->op1.constant+1])); + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); break; default: opline->op1.constant = zend_optimizer_add_literal(op_array, val); @@ -195,23 +200,17 @@ void zend_optimizer_update_op2_const(zend_op_array *op_array, case ZEND_INSTANCEOF: Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; op_array->cache_size += sizeof(void*); - zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); - zend_optimizer_add_literal(op_array, val); - zend_string_hash_val(Z_STR(op_array->literals[opline->op2.constant+1])); + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); break; case ZEND_INIT_DYNAMIC_CALL: opline->opcode = ZEND_INIT_FCALL_BY_NAME; Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; op_array->cache_size += sizeof(void*); - zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); - zend_optimizer_add_literal(op_array, val); - zend_string_hash_val(Z_STR(op_array->literals[opline->op2.constant+1])); + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); break; case ZEND_INIT_METHOD_CALL: case ZEND_INIT_STATIC_METHOD_CALL: - zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); - zend_optimizer_add_literal(op_array, val); - zend_string_hash_val(Z_STR(op_array->literals[opline->op2.constant+1])); + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); /* break missing intentionally */ /*case ZEND_FETCH_CONSTANT:*/ case ZEND_ASSIGN_OBJ: From 00b37e718d002612e1a3cfcc01f62b9a64826960 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 7 Nov 2015 10:59:18 +0100 Subject: [PATCH 47/65] Strip leading backslash in update_opN_const --- ...tic_prop_on_expr_class_with_backslash.phpt | 13 ++++++ ext/opcache/Optimizer/zend_optimizer.c | 43 ++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 Zend/tests/varSyntax/static_prop_on_expr_class_with_backslash.phpt diff --git a/Zend/tests/varSyntax/static_prop_on_expr_class_with_backslash.phpt b/Zend/tests/varSyntax/static_prop_on_expr_class_with_backslash.phpt new file mode 100644 index 0000000000..c78610401f --- /dev/null +++ b/Zend/tests/varSyntax/static_prop_on_expr_class_with_backslash.phpt @@ -0,0 +1,13 @@ +--TEST-- +Static property on constexpr class with leading backslash +--FILE-- + +--EXPECT-- +int(42) diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 1f5e4f1bf6..153de18e46 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -124,6 +124,14 @@ int zend_optimizer_is_disabled_func(const char *name, size_t len) { fbc->internal_function.handler == ZEND_FN(display_disabled_function)); } +static inline void drop_leading_backslash(zval *val) { + if (Z_STRVAL_P(val)[0] == '\\') { + zend_string *str = zend_string_init(Z_STRVAL_P(val) + 1, Z_STRLEN_P(val) - 1, 0); + zval_dtor(val); + ZVAL_STR(val, str); + } +} + void zend_optimizer_update_op1_const(zend_op_array *op_array, zend_op *opline, zval *val) @@ -140,6 +148,7 @@ void zend_optimizer_update_op1_const(zend_op_array *op_array, case ZEND_FETCH_CONSTANT: case ZEND_DEFINED: case ZEND_NEW: + drop_leading_backslash(val); opline->op1.constant = zend_optimizer_add_literal(op_array, val); zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->cache_size; @@ -173,13 +182,35 @@ void zend_optimizer_update_op2_const(zend_op_array *op_array, Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; op_array->cache_size += sizeof(void*); return; - } else if (opline->opcode == ZEND_ROPE_INIT || - opline->opcode == ZEND_ROPE_ADD || - opline->opcode == ZEND_ROPE_END || - opline->opcode == ZEND_CONCAT || - opline->opcode == ZEND_FAST_CONCAT) { - convert_to_string(val); } + + switch (opline->opcode) { + case ZEND_ROPE_INIT: + case ZEND_ROPE_ADD: + case ZEND_ROPE_END: + case ZEND_CONCAT: + case ZEND_FAST_CONCAT: + convert_to_string(val); + break; + case ZEND_FETCH_R: + case ZEND_FETCH_W: + case ZEND_FETCH_RW: + case ZEND_FETCH_IS: + case ZEND_FETCH_UNSET: + case ZEND_FETCH_FUNC_ARG: + case ZEND_FETCH_CLASS: + case ZEND_INIT_FCALL_BY_NAME: + /*case ZEND_INIT_NS_FCALL_BY_NAME:*/ + case ZEND_UNSET_VAR: + case ZEND_ISSET_ISEMPTY_VAR: + case ZEND_ADD_INTERFACE: + case ZEND_ADD_TRAIT: + case ZEND_INSTANCEOF: + case ZEND_INIT_DYNAMIC_CALL: + drop_leading_backslash(val); + break; + } + opline->op2.constant = zend_optimizer_add_literal(op_array, val); if (Z_TYPE_P(val) == IS_STRING) { zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline))); From 99d818f1e901d4eb411a6458a7800df071d8284a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 7 Nov 2015 11:48:21 +0100 Subject: [PATCH 48/65] Don't propagate into ops that error on non-string To properly support this make update_opN_const fallible -- they are not always called through replace_with_const. --- .../static_prop_on_int_expr_class.phpt | 11 +++ ext/opcache/Optimizer/block_pass.c | 24 +++-- ext/opcache/Optimizer/zend_optimizer.c | 92 ++++++++++--------- .../Optimizer/zend_optimizer_internal.h | 12 +-- 4 files changed, 82 insertions(+), 57 deletions(-) create mode 100644 Zend/tests/varSyntax/static_prop_on_int_expr_class.phpt diff --git a/Zend/tests/varSyntax/static_prop_on_int_expr_class.phpt b/Zend/tests/varSyntax/static_prop_on_int_expr_class.phpt new file mode 100644 index 0000000000..c7c44d5694 --- /dev/null +++ b/Zend/tests/varSyntax/static_prop_on_int_expr_class.phpt @@ -0,0 +1,11 @@ +--TEST-- +Static property access on constexpr class evaluating to integer +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: Class name must be a valid object or a string in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c index b7e1682866..210078e7a9 100644 --- a/ext/opcache/Optimizer/block_pass.c +++ b/ext/opcache/Optimizer/block_pass.c @@ -643,13 +643,15 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array, (opline->opcode != ZEND_FE_RESET_R || opline->opcode != ZEND_FE_RESET_RW) && opline->opcode != ZEND_FREE ) { - zend_op *src = VAR_SOURCE(opline->op1); + znode_op op1 = opline->op1; + zend_op *src = VAR_SOURCE(op1); zval c = ZEND_OP1_LITERAL(src); - VAR_UNSET(opline->op1); zval_copy_ctor(&c); - zend_optimizer_update_op1_const(op_array, opline, &c); - literal_dtor(&ZEND_OP1_LITERAL(src)); - MAKE_NOP(src); + if (zend_optimizer_update_op1_const(op_array, opline, &c)) { + VAR_SOURCE(op1) = NULL; + literal_dtor(&ZEND_OP1_LITERAL(src)); + MAKE_NOP(src); + } } /* T = QM_ASSIGN(C), F(T) => NOP, F(C) */ @@ -657,13 +659,15 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array, VAR_SOURCE(opline->op2) && VAR_SOURCE(opline->op2)->opcode == ZEND_QM_ASSIGN && ZEND_OP1_TYPE(VAR_SOURCE(opline->op2)) == IS_CONST) { - zend_op *src = VAR_SOURCE(opline->op2); + znode_op op2 = opline->op2; + zend_op *src = VAR_SOURCE(op2); zval c = ZEND_OP1_LITERAL(src); - VAR_UNSET(opline->op2); zval_copy_ctor(&c); - zend_optimizer_update_op2_const(op_array, opline, &c); - literal_dtor(&ZEND_OP1_LITERAL(src)); - MAKE_NOP(src); + if (zend_optimizer_update_op2_const(op_array, opline, &c)) { + VAR_SOURCE(op2) = NULL; + literal_dtor(&ZEND_OP1_LITERAL(src)); + MAKE_NOP(src); + } } /* T = CAST(X, String), ECHO(T) => NOP, ECHO(X) */ diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 153de18e46..9e13b6497e 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -132,56 +132,60 @@ static inline void drop_leading_backslash(zval *val) { } } -void zend_optimizer_update_op1_const(zend_op_array *op_array, - zend_op *opline, - zval *val) +int zend_optimizer_update_op1_const(zend_op_array *op_array, + zend_op *opline, + zval *val) { - if (opline->opcode == ZEND_FREE) { - MAKE_NOP(opline); - zval_dtor(val); - } else { - ZEND_OP1_TYPE(opline) = IS_CONST; - if (Z_TYPE_P(val) == IS_STRING) { - switch (opline->opcode) { - case ZEND_INIT_STATIC_METHOD_CALL: - case ZEND_CATCH: - case ZEND_FETCH_CONSTANT: - case ZEND_DEFINED: - case ZEND_NEW: - drop_leading_backslash(val); - opline->op1.constant = zend_optimizer_add_literal(op_array, val); - zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); - Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->cache_size; - op_array->cache_size += sizeof(void*); - zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); - break; - default: - opline->op1.constant = zend_optimizer_add_literal(op_array, val); - zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); - break; - } - } else { - if (opline->opcode == ZEND_CONCAT || - opline->opcode == ZEND_FAST_CONCAT) { - convert_to_string(val); + switch (opline->opcode) { + case ZEND_FREE: + MAKE_NOP(opline); + zval_dtor(val); + break; + case ZEND_INIT_STATIC_METHOD_CALL: + case ZEND_CATCH: + case ZEND_FETCH_CONSTANT: + case ZEND_DEFINED: + case ZEND_NEW: + if (Z_TYPE_P(val) != IS_STRING) { + zval_dtor(val); + return 0; } + ZEND_OP1_TYPE(opline) = IS_CONST; + drop_leading_backslash(val); opline->op1.constant = zend_optimizer_add_literal(op_array, val); - } + zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); + Z_CACHE_SLOT(op_array->literals[opline->op1.constant]) = op_array->cache_size; + op_array->cache_size += sizeof(void*); + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); + break; + case ZEND_CONCAT: + case ZEND_FAST_CONCAT: + convert_to_string(val); + /* break missing intentionally */ + default: + ZEND_OP1_TYPE(opline) = IS_CONST; + opline->op1.constant = zend_optimizer_add_literal(op_array, val); + if (Z_TYPE_P(val) == IS_STRING) { + zend_string_hash_val(Z_STR(ZEND_OP1_LITERAL(opline))); + } + break; } + + return 1; } -void zend_optimizer_update_op2_const(zend_op_array *op_array, - zend_op *opline, - zval *val) +int zend_optimizer_update_op2_const(zend_op_array *op_array, + zend_op *opline, + zval *val) { - ZEND_OP2_TYPE(opline) = IS_CONST; if (opline->opcode == ZEND_INIT_FCALL) { + ZEND_OP2_TYPE(opline) = IS_CONST; zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); opline->op2.constant = zend_optimizer_add_literal(op_array, val); zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline))); Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; op_array->cache_size += sizeof(void*); - return; + return 1; } switch (opline->opcode) { @@ -206,11 +210,17 @@ void zend_optimizer_update_op2_const(zend_op_array *op_array, case ZEND_ADD_INTERFACE: case ZEND_ADD_TRAIT: case ZEND_INSTANCEOF: + if (Z_TYPE_P(val) != IS_STRING) { + zval_dtor(val); + return 0; + } + /* break missing intentionally */ case ZEND_INIT_DYNAMIC_CALL: drop_leading_backslash(val); break; } + ZEND_OP2_TYPE(opline) = IS_CONST; opline->op2.constant = zend_optimizer_add_literal(op_array, val); if (Z_TYPE_P(val) == IS_STRING) { zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline))); @@ -322,6 +332,8 @@ check_numeric: break; } } + + return 1; } int zend_optimizer_replace_by_const(zend_op_array *op_array, @@ -429,8 +441,7 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array, default: break; } - zend_optimizer_update_op1_const(op_array, opline, val); - break; + return zend_optimizer_update_op1_const(op_array, opline, val); } if (ZEND_OP2_TYPE(opline) == type && @@ -442,8 +453,7 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array, default: break; } - zend_optimizer_update_op2_const(op_array, opline, val); - break; + return zend_optimizer_update_op2_const(op_array, opline, val); } opline++; } diff --git a/ext/opcache/Optimizer/zend_optimizer_internal.h b/ext/opcache/Optimizer/zend_optimizer_internal.h index ca452670d7..90df3cfadc 100644 --- a/ext/opcache/Optimizer/zend_optimizer_internal.h +++ b/ext/opcache/Optimizer/zend_optimizer_internal.h @@ -118,12 +118,12 @@ int zend_optimizer_get_persistent_constant(zend_string *name, zval *result, int void zend_optimizer_collect_constant(zend_optimizer_ctx *ctx, zval *name, zval* value); int zend_optimizer_get_collected_constant(HashTable *constants, zval *name, zval* value); int zend_optimizer_lookup_cv(zend_op_array *op_array, zend_string* name); -void zend_optimizer_update_op1_const(zend_op_array *op_array, - zend_op *opline, - zval *val); -void zend_optimizer_update_op2_const(zend_op_array *op_array, - zend_op *opline, - zval *val); +int zend_optimizer_update_op1_const(zend_op_array *op_array, + zend_op *opline, + zval *val); +int zend_optimizer_update_op2_const(zend_op_array *op_array, + zend_op *opline, + zval *val); int zend_optimizer_replace_by_const(zend_op_array *op_array, zend_op *opline, zend_uchar type, From 0bf3ebb4ba77f38261d9cb21a205a7d31b7f85cf Mon Sep 17 00:00:00 2001 From: Reeze Xia Date: Sat, 7 Nov 2015 21:46:21 +0800 Subject: [PATCH 49/65] Fixed bug #70876 Segmentation fault when regenerating session id with strict mode The comment *mod_data always be non-NULL is not true. The same as this FIXME: https://github.com/php/php-src/blob/master/ext/session/mod_files.c#L676 --- ext/session/mod_files.c | 4 ++++ ext/session/tests/bug70876.phpt | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 ext/session/tests/bug70876.phpt diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c index 8301b73f5e..933df93ca8 100644 --- a/ext/session/mod_files.c +++ b/ext/session/mod_files.c @@ -702,6 +702,10 @@ PS_VALIDATE_SID_FUNC(files) { PS_FILES_DATA; + if (!data) { + return FAILURE; + } + return ps_files_key_exists(data, ZSTR_VAL(key)); } diff --git a/ext/session/tests/bug70876.phpt b/ext/session/tests/bug70876.phpt new file mode 100644 index 0000000000..33e0323b9f --- /dev/null +++ b/ext/session/tests/bug70876.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #70876 Segmentation fault when regenerating session id with strict mode +--SKIPIF-- + +--INI-- +html_errors=0 +session.save_handler=files +--FILE-- + +--EXPECT-- +ok \ No newline at end of file From e4c1e90536ca00ed030335f4162902b3f06125b0 Mon Sep 17 00:00:00 2001 From: Reeze Xia Date: Sat, 7 Nov 2015 22:10:56 +0800 Subject: [PATCH 50/65] Update NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 2cd4e2b6e7..e68dc23819 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,10 @@ PHP NEWS . Fix bug #70861 (Segmentation fault in pdo_parse_params() during Drupal 8 test suite). (Anatol) +- Session: + . Fixed bug #70876 (Segmentation fault when regenerating session id with + strict mode). (Reeze Xia) + - SOAP: . Fixed bug #70875 (Segmentation fault if wsdl has no targetNamespace attribute). (Matteo) From c524f43e4f6869854d03e11336ddbccab255887a Mon Sep 17 00:00:00 2001 From: Reeze Xia Date: Sat, 7 Nov 2015 22:15:19 +0800 Subject: [PATCH 51/65] C99 complain fix --- ext/opcache/zend_file_cache.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index d1ea0a46a6..7c615e927b 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -36,6 +36,10 @@ #include #include +#if HAVE_UNISTD_H +#include +#endif + #ifdef HAVE_SYS_UIO_H # include #endif From 2d8d97cee25b632b21d4740c0c7c077196603e9d Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 7 Nov 2015 06:50:24 -0800 Subject: [PATCH 52/65] Fixed bug #70873 (Regression on private static properties access) --- NEWS | 2 ++ Zend/tests/bug70873.phpt | 34 ++++++++++++++++++++++++++++++++++ Zend/zend_object_handlers.c | 4 ++-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/bug70873.phpt diff --git a/NEWS b/NEWS index e68dc23819..95aab2c0c1 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ PHP NEWS ?? ??? 2015, PHP 7.0.1 - Core: + . Fixed bug #70873 (Regression on private static properties access). + (Laruence) . Fixed bug #70805 (Segmentation faults whilst running Drupal 8 test suite). (Dmitry, Laruence) . Fixed bug #70862 (Several functions do not check return code of diff --git a/Zend/tests/bug70873.phpt b/Zend/tests/bug70873.phpt new file mode 100644 index 0000000000..3edb7eac43 --- /dev/null +++ b/Zend/tests/bug70873.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #70873 (Regression on private static properties access) +--FILE-- +bar(); + +$b = new C; +$b->bar(); +?> +--EXPECTF-- +Fatal error: Uncaught Error: Cannot access property B::$x in %sbug70873.php:%d +Stack trace: +#0 %sbug70873.php(%d): B->bar() +#1 {main} + thrown in %sbug70873.php on line %d diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 7c4b6a679a..4cd8a4e7c2 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -275,10 +275,10 @@ static zend_always_inline int zend_verify_property_access(zend_property_info *pr return 1; } else if (property_info->flags & ZEND_ACC_PRIVATE) { return (ce == EG(scope) || property_info->ce == EG(scope)); - } else { - ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED); + } else if (property_info->flags & ZEND_ACC_PROTECTED) { return zend_check_protected(property_info->ce, EG(scope)); } + return 0; } /* }}} */ From 148bb622faa71090a3f6d9721aeb28a4ac720496 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 7 Nov 2015 07:17:43 -0800 Subject: [PATCH 53/65] Revert "Fixed bug #70876 Segmentation fault when regenerating session id with strict mode" This reverts commit 0bf3ebb4ba77f38261d9cb21a205a7d31b7f85cf. --- ext/session/mod_files.c | 4 ---- ext/session/tests/bug70876.phpt | 17 ----------------- 2 files changed, 21 deletions(-) delete mode 100644 ext/session/tests/bug70876.phpt diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c index 933df93ca8..8301b73f5e 100644 --- a/ext/session/mod_files.c +++ b/ext/session/mod_files.c @@ -702,10 +702,6 @@ PS_VALIDATE_SID_FUNC(files) { PS_FILES_DATA; - if (!data) { - return FAILURE; - } - return ps_files_key_exists(data, ZSTR_VAL(key)); } diff --git a/ext/session/tests/bug70876.phpt b/ext/session/tests/bug70876.phpt deleted file mode 100644 index 33e0323b9f..0000000000 --- a/ext/session/tests/bug70876.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Bug #70876 Segmentation fault when regenerating session id with strict mode ---SKIPIF-- - ---INI-- -html_errors=0 -session.save_handler=files ---FILE-- - ---EXPECT-- -ok \ No newline at end of file From e9fd8ad4462a39f61e757ef89f417c413aa1df6f Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 7 Nov 2015 07:30:31 -0800 Subject: [PATCH 54/65] Fixed bug #70876 (Segmentation fault when regenerating session id with strict mode) --- NEWS | 2 +- ext/session/session.c | 10 +++++----- ext/session/tests/bug70876.phpt | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 ext/session/tests/bug70876.phpt diff --git a/NEWS b/NEWS index 95aab2c0c1..8f3ff128b1 100644 --- a/NEWS +++ b/NEWS @@ -24,7 +24,7 @@ PHP NEWS - Session: . Fixed bug #70876 (Segmentation fault when regenerating session id with - strict mode). (Reeze Xia) + strict mode). (Laruence) - SOAP: . Fixed bug #70875 (Segmentation fault if wsdl has no targetNamespace diff --git a/ext/session/session.c b/ext/session/session.c index 570173a838..dd8651883d 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -2077,6 +2077,11 @@ static PHP_FUNCTION(session_regenerate_id) php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); RETURN_FALSE; } + if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) { + PS(session_status) = php_session_none; + php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); + RETURN_FALSE; + } if (PS(use_strict_mode) && PS(mod)->s_validate_sid && PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE) { zend_string_release(PS(id)); @@ -2087,11 +2092,6 @@ static PHP_FUNCTION(session_regenerate_id) RETURN_FALSE; } } - if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) { - PS(session_status) = php_session_none; - php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); - RETURN_FALSE; - } /* Read is required to make new session data at this point. */ if (PS(mod)->s_read(&PS(mod_data), PS(id), &data, PS(gc_maxlifetime)) == FAILURE) { PS(session_status) = php_session_none; diff --git a/ext/session/tests/bug70876.phpt b/ext/session/tests/bug70876.phpt new file mode 100644 index 0000000000..33e0323b9f --- /dev/null +++ b/ext/session/tests/bug70876.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #70876 Segmentation fault when regenerating session id with strict mode +--SKIPIF-- + +--INI-- +html_errors=0 +session.save_handler=files +--FILE-- + +--EXPECT-- +ok \ No newline at end of file From de8bfb32bd1696a0420b36086a333abf0714a2a1 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 7 Nov 2015 07:43:18 -0800 Subject: [PATCH 55/65] Use defined macro --- ext/session/mod_files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c index 8301b73f5e..e68cde2972 100644 --- a/ext/session/mod_files.c +++ b/ext/session/mod_files.c @@ -443,7 +443,7 @@ PS_CLOSE_FUNC(files) efree(data->basedir); efree(data); - *mod_data = NULL; + PS_SET_MOD_DATA(NULL); return SUCCESS; } From 9da456655c56da3bf3099777fe5dec887f964bfd Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 7 Nov 2015 17:27:12 +0100 Subject: [PATCH 56/65] Refactor update_op2_const Combines both switches into one, to avoid having to maintain the same opcode list twice. This also makes most of the bugs fixed by the next commit pretty obvious. No functional change here. --- ext/opcache/Optimizer/zend_optimizer.c | 262 ++++++++++++------------- 1 file changed, 126 insertions(+), 136 deletions(-) diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 9e13b6497e..81f5060c61 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -132,6 +132,11 @@ static inline void drop_leading_backslash(zval *val) { } } +static inline void alloc_cache_slots_op2(zend_op_array *op_array, zend_op *opline, uint32_t num) { + Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; + op_array->cache_size += num * sizeof(void *); +} + int zend_optimizer_update_op1_const(zend_op_array *op_array, zend_op *opline, zval *val) @@ -178,24 +183,10 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array, zend_op *opline, zval *val) { - if (opline->opcode == ZEND_INIT_FCALL) { - ZEND_OP2_TYPE(opline) = IS_CONST; - zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); - opline->op2.constant = zend_optimizer_add_literal(op_array, val); - zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline))); - Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; - op_array->cache_size += sizeof(void*); - return 1; - } - switch (opline->opcode) { - case ZEND_ROPE_INIT: - case ZEND_ROPE_ADD: - case ZEND_ROPE_END: - case ZEND_CONCAT: - case ZEND_FAST_CONCAT: - convert_to_string(val); - break; + case ZEND_ASSIGN_REF: + zval_dtor(val); + return 0; case ZEND_FETCH_R: case ZEND_FETCH_W: case ZEND_FETCH_RW: @@ -214,125 +205,131 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array, zval_dtor(val); return 0; } - /* break missing intentionally */ - case ZEND_INIT_DYNAMIC_CALL: + drop_leading_backslash(val); + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); + alloc_cache_slots_op2(op_array, opline, 1); + break; + case ZEND_INIT_FCALL: + zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + alloc_cache_slots_op2(op_array, opline, 1); + break; + case ZEND_INIT_DYNAMIC_CALL: + if (Z_TYPE_P(val) == IS_STRING) { + opline->opcode = ZEND_INIT_FCALL_BY_NAME; + drop_leading_backslash(val); + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); + alloc_cache_slots_op2(op_array, opline, 1); + } else { + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + } + break; + case ZEND_INIT_METHOD_CALL: + case ZEND_INIT_STATIC_METHOD_CALL: + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + if (Z_TYPE_P(val) == IS_STRING) { + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); + alloc_cache_slots_op2(op_array, opline, 2); + } + break; + /*case ZEND_FETCH_CONSTANT:*/ + case ZEND_ASSIGN_OBJ: + case ZEND_FETCH_OBJ_R: + case ZEND_FETCH_OBJ_W: + case ZEND_FETCH_OBJ_RW: + case ZEND_FETCH_OBJ_IS: + case ZEND_FETCH_OBJ_UNSET: + case ZEND_FETCH_OBJ_FUNC_ARG: + case ZEND_UNSET_OBJ: + case ZEND_PRE_INC_OBJ: + case ZEND_PRE_DEC_OBJ: + case ZEND_POST_INC_OBJ: + case ZEND_POST_DEC_OBJ: + case ZEND_ISSET_ISEMPTY_PROP_OBJ: + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + if (Z_TYPE_P(val) == IS_STRING) { + alloc_cache_slots_op2(op_array, opline, 2); + } + break; + case ZEND_ASSIGN_ADD: + case ZEND_ASSIGN_SUB: + case ZEND_ASSIGN_MUL: + case ZEND_ASSIGN_DIV: + case ZEND_ASSIGN_POW: + case ZEND_ASSIGN_MOD: + case ZEND_ASSIGN_SL: + case ZEND_ASSIGN_SR: + case ZEND_ASSIGN_CONCAT: + case ZEND_ASSIGN_BW_OR: + case ZEND_ASSIGN_BW_AND: + case ZEND_ASSIGN_BW_XOR: + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + if (Z_TYPE_P(val) == IS_STRING) { + if (opline->extended_value == ZEND_ASSIGN_OBJ) { + alloc_cache_slots_op2(op_array, opline, 2); + } + } + break; + case ZEND_OP_DATA: + if ((opline-1)->opcode != ZEND_ASSIGN_DIM && + ((opline-1)->extended_value != ZEND_ASSIGN_DIM || + ((opline-1)->opcode != ZEND_ASSIGN_ADD && + (opline-1)->opcode != ZEND_ASSIGN_SUB && + (opline-1)->opcode != ZEND_ASSIGN_MUL && + (opline-1)->opcode != ZEND_ASSIGN_DIV && + (opline-1)->opcode != ZEND_ASSIGN_POW && + (opline-1)->opcode != ZEND_ASSIGN_MOD && + (opline-1)->opcode != ZEND_ASSIGN_SL && + (opline-1)->opcode != ZEND_ASSIGN_SR && + (opline-1)->opcode != ZEND_ASSIGN_CONCAT && + (opline-1)->opcode != ZEND_ASSIGN_BW_OR && + (opline-1)->opcode != ZEND_ASSIGN_BW_AND && + (opline-1)->opcode != ZEND_ASSIGN_BW_XOR)) + ) { + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + break; + } + /* break missing intentionally */ + case ZEND_ISSET_ISEMPTY_DIM_OBJ: + case ZEND_ADD_ARRAY_ELEMENT: + case ZEND_INIT_ARRAY: + case ZEND_ASSIGN_DIM: + case ZEND_UNSET_DIM: + case ZEND_FETCH_DIM_R: + case ZEND_FETCH_DIM_W: + case ZEND_FETCH_DIM_RW: + case ZEND_FETCH_DIM_IS: + case ZEND_FETCH_DIM_FUNC_ARG: + case ZEND_FETCH_DIM_UNSET: + case ZEND_FETCH_LIST: + if (Z_TYPE_P(val) == IS_STRING) { + zend_ulong index; + if (ZEND_HANDLE_NUMERIC(Z_STR_P(val), index)) { + zval_dtor(val); + ZVAL_LONG(val, index); + } + } + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + break; + case ZEND_ROPE_INIT: + case ZEND_ROPE_ADD: + case ZEND_ROPE_END: + case ZEND_CONCAT: + case ZEND_FAST_CONCAT: + convert_to_string(val); + /* break missing intentionally */ + default: + opline->op2.constant = zend_optimizer_add_literal(op_array, val); break; } ZEND_OP2_TYPE(opline) = IS_CONST; - opline->op2.constant = zend_optimizer_add_literal(op_array, val); - if (Z_TYPE_P(val) == IS_STRING) { + if (Z_TYPE(ZEND_OP2_LITERAL(opline)) == IS_STRING) { zend_string_hash_val(Z_STR(ZEND_OP2_LITERAL(opline))); - switch (opline->opcode) { - case ZEND_FETCH_R: - case ZEND_FETCH_W: - case ZEND_FETCH_RW: - case ZEND_FETCH_IS: - case ZEND_FETCH_UNSET: - case ZEND_FETCH_FUNC_ARG: - case ZEND_FETCH_CLASS: - case ZEND_INIT_FCALL_BY_NAME: - /*case ZEND_INIT_NS_FCALL_BY_NAME:*/ - case ZEND_UNSET_VAR: - case ZEND_ISSET_ISEMPTY_VAR: - case ZEND_ADD_INTERFACE: - case ZEND_ADD_TRAIT: - case ZEND_INSTANCEOF: - Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; - op_array->cache_size += sizeof(void*); - zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); - break; - case ZEND_INIT_DYNAMIC_CALL: - opline->opcode = ZEND_INIT_FCALL_BY_NAME; - Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; - op_array->cache_size += sizeof(void*); - zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); - break; - case ZEND_INIT_METHOD_CALL: - case ZEND_INIT_STATIC_METHOD_CALL: - zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); - /* break missing intentionally */ - /*case ZEND_FETCH_CONSTANT:*/ - case ZEND_ASSIGN_OBJ: - case ZEND_FETCH_OBJ_R: - case ZEND_FETCH_OBJ_W: - case ZEND_FETCH_OBJ_RW: - case ZEND_FETCH_OBJ_IS: - case ZEND_FETCH_OBJ_UNSET: - case ZEND_FETCH_OBJ_FUNC_ARG: - case ZEND_UNSET_OBJ: - case ZEND_PRE_INC_OBJ: - case ZEND_PRE_DEC_OBJ: - case ZEND_POST_INC_OBJ: - case ZEND_POST_DEC_OBJ: - case ZEND_ISSET_ISEMPTY_PROP_OBJ: - Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; - op_array->cache_size += 2 * sizeof(void*); - break; - case ZEND_ASSIGN_ADD: - case ZEND_ASSIGN_SUB: - case ZEND_ASSIGN_MUL: - case ZEND_ASSIGN_DIV: - case ZEND_ASSIGN_POW: - case ZEND_ASSIGN_MOD: - case ZEND_ASSIGN_SL: - case ZEND_ASSIGN_SR: - case ZEND_ASSIGN_CONCAT: - case ZEND_ASSIGN_BW_OR: - case ZEND_ASSIGN_BW_AND: - case ZEND_ASSIGN_BW_XOR: - if (opline->extended_value == ZEND_ASSIGN_OBJ) { - Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = op_array->cache_size; - op_array->cache_size += 2 * sizeof(void*); - } - break; - case ZEND_OP_DATA: - if ((opline-1)->opcode == ZEND_ASSIGN_DIM || - ((opline-1)->extended_value == ZEND_ASSIGN_DIM && - ((opline-1)->opcode == ZEND_ASSIGN_ADD || - (opline-1)->opcode == ZEND_ASSIGN_SUB || - (opline-1)->opcode == ZEND_ASSIGN_MUL || - (opline-1)->opcode == ZEND_ASSIGN_DIV || - (opline-1)->opcode == ZEND_ASSIGN_POW || - (opline-1)->opcode == ZEND_ASSIGN_MOD || - (opline-1)->opcode == ZEND_ASSIGN_SL || - (opline-1)->opcode == ZEND_ASSIGN_SR || - (opline-1)->opcode == ZEND_ASSIGN_CONCAT || - (opline-1)->opcode == ZEND_ASSIGN_BW_OR || - (opline-1)->opcode == ZEND_ASSIGN_BW_AND || - (opline-1)->opcode == ZEND_ASSIGN_BW_XOR))) { - goto check_numeric; - } - break; - case ZEND_ISSET_ISEMPTY_DIM_OBJ: - case ZEND_ADD_ARRAY_ELEMENT: - case ZEND_INIT_ARRAY: - case ZEND_ASSIGN_DIM: - case ZEND_UNSET_DIM: - case ZEND_FETCH_DIM_R: - case ZEND_FETCH_DIM_W: - case ZEND_FETCH_DIM_RW: - case ZEND_FETCH_DIM_IS: - case ZEND_FETCH_DIM_FUNC_ARG: - case ZEND_FETCH_DIM_UNSET: - case ZEND_FETCH_LIST: -check_numeric: - { - zend_ulong index; - - if (ZEND_HANDLE_NUMERIC(Z_STR_P(val), index)) { - zval_dtor(val); - ZVAL_LONG(val, index); - op_array->literals[opline->op2.constant] = *val; - } - } - break; - default: - break; - } } - return 1; } @@ -446,13 +443,6 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array, if (ZEND_OP2_TYPE(opline) == type && ZEND_OP2(opline).var == var) { - switch (opline->opcode) { - case ZEND_ASSIGN_REF: - zval_dtor(val); - return 0; - default: - break; - } return zend_optimizer_update_op2_const(op_array, opline, val); } opline++; From bc3512c1d6857de2d3908c4865328e7947e13493 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 7 Nov 2015 17:45:26 +0100 Subject: [PATCH 57/65] Fix various update_opN_const issues --- ext/opcache/Optimizer/zend_optimizer.c | 64 +++++++++++++++++--------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/ext/opcache/Optimizer/zend_optimizer.c b/ext/opcache/Optimizer/zend_optimizer.c index 81f5060c61..aa5b6a8a23 100644 --- a/ext/opcache/Optimizer/zend_optimizer.c +++ b/ext/opcache/Optimizer/zend_optimizer.c @@ -137,6 +137,21 @@ static inline void alloc_cache_slots_op2(zend_op_array *op_array, zend_op *oplin op_array->cache_size += num * sizeof(void *); } +#define REQUIRES_STRING(val) do { \ + if (Z_TYPE_P(val) != IS_STRING) { \ + zval_dtor(val); \ + return 0; \ + } \ +} while (0) + +#define TO_STRING_NOWARN(val) do { \ + if (Z_TYPE_P(val) >= IS_ARRAY) { \ + zval_dtor(val); \ + return 0; \ + } \ + convert_to_string(val); \ +} while (0) + int zend_optimizer_update_op1_const(zend_op_array *op_array, zend_op *opline, zval *val) @@ -151,10 +166,7 @@ int zend_optimizer_update_op1_const(zend_op_array *op_array, case ZEND_FETCH_CONSTANT: case ZEND_DEFINED: case ZEND_NEW: - if (Z_TYPE_P(val) != IS_STRING) { - zval_dtor(val); - return 0; - } + REQUIRES_STRING(val); ZEND_OP1_TYPE(opline) = IS_CONST; drop_leading_backslash(val); opline->op1.constant = zend_optimizer_add_literal(op_array, val); @@ -165,7 +177,7 @@ int zend_optimizer_update_op1_const(zend_op_array *op_array, break; case ZEND_CONCAT: case ZEND_FAST_CONCAT: - convert_to_string(val); + TO_STRING_NOWARN(val); /* break missing intentionally */ default: ZEND_OP1_TYPE(opline) = IS_CONST; @@ -201,23 +213,25 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array, case ZEND_ADD_INTERFACE: case ZEND_ADD_TRAIT: case ZEND_INSTANCEOF: - if (Z_TYPE_P(val) != IS_STRING) { - zval_dtor(val); - return 0; - } - + REQUIRES_STRING(val); drop_leading_backslash(val); opline->op2.constant = zend_optimizer_add_literal(op_array, val); zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); alloc_cache_slots_op2(op_array, opline, 1); break; case ZEND_INIT_FCALL: + REQUIRES_STRING(val); zend_str_tolower(Z_STRVAL_P(val), Z_STRLEN_P(val)); opline->op2.constant = zend_optimizer_add_literal(op_array, val); alloc_cache_slots_op2(op_array, opline, 1); break; case ZEND_INIT_DYNAMIC_CALL: if (Z_TYPE_P(val) == IS_STRING) { + if (zend_memrchr(Z_STRVAL_P(val), ':', Z_STRLEN_P(val))) { + zval_dtor(val); + return 0; + } + opline->opcode = ZEND_INIT_FCALL_BY_NAME; drop_leading_backslash(val); opline->op2.constant = zend_optimizer_add_literal(op_array, val); @@ -229,11 +243,10 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array, break; case ZEND_INIT_METHOD_CALL: case ZEND_INIT_STATIC_METHOD_CALL: + REQUIRES_STRING(val); opline->op2.constant = zend_optimizer_add_literal(op_array, val); - if (Z_TYPE_P(val) == IS_STRING) { - zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); - alloc_cache_slots_op2(op_array, opline, 2); - } + zend_optimizer_add_literal_string(op_array, zend_string_tolower(Z_STR_P(val))); + alloc_cache_slots_op2(op_array, opline, 2); break; /*case ZEND_FETCH_CONSTANT:*/ case ZEND_ASSIGN_OBJ: @@ -249,10 +262,9 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array, case ZEND_POST_INC_OBJ: case ZEND_POST_DEC_OBJ: case ZEND_ISSET_ISEMPTY_PROP_OBJ: + TO_STRING_NOWARN(val); opline->op2.constant = zend_optimizer_add_literal(op_array, val); - if (Z_TYPE_P(val) == IS_STRING) { - alloc_cache_slots_op2(op_array, opline, 2); - } + alloc_cache_slots_op2(op_array, opline, 2); break; case ZEND_ASSIGN_ADD: case ZEND_ASSIGN_SUB: @@ -266,11 +278,12 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array, case ZEND_ASSIGN_BW_OR: case ZEND_ASSIGN_BW_AND: case ZEND_ASSIGN_BW_XOR: - opline->op2.constant = zend_optimizer_add_literal(op_array, val); - if (Z_TYPE_P(val) == IS_STRING) { - if (opline->extended_value == ZEND_ASSIGN_OBJ) { - alloc_cache_slots_op2(op_array, opline, 2); - } + if (opline->extended_value == ZEND_ASSIGN_OBJ) { + TO_STRING_NOWARN(val); + opline->op2.constant = zend_optimizer_add_literal(op_array, val); + alloc_cache_slots_op2(op_array, opline, 2); + } else { + opline->op2.constant = zend_optimizer_add_literal(op_array, val); } break; case ZEND_OP_DATA: @@ -319,7 +332,7 @@ int zend_optimizer_update_op2_const(zend_op_array *op_array, case ZEND_ROPE_END: case ZEND_CONCAT: case ZEND_FAST_CONCAT: - convert_to_string(val); + TO_STRING_NOWARN(val); /* break missing intentionally */ default: opline->op2.constant = zend_optimizer_add_literal(op_array, val); @@ -351,6 +364,8 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array, case ZEND_FETCH_DIM_UNSET: case ZEND_ASSIGN_DIM: case ZEND_SEPARATE: + case ZEND_RETURN_BY_REF: + zval_dtor(val); return 0; case ZEND_SEND_VAR: opline->extended_value = 0; @@ -373,6 +388,9 @@ int zend_optimizer_replace_by_const(zend_op_array *op_array, opline->opcode = ZEND_SEND_VAL; } break; + case ZEND_SEND_USER: + opline->opcode = ZEND_SEND_VAL_EX; + break; /* In most cases IS_TMP_VAR operand may be used only once. * The operands are usually destroyed by the opcode handler. * ZEND_CASE is an exception, that keeps operand unchanged, From 55abf6dfb26f687b2903885267e104f76902042b Mon Sep 17 00:00:00 2001 From: Colin O'Dell Date: Sat, 7 Nov 2015 17:48:02 -0500 Subject: [PATCH 58/65] Fix description of a BC break --- UPGRADING | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADING b/UPGRADING index 1e38a294e8..9faf7c7ce6 100644 --- a/UPGRADING +++ b/UPGRADING @@ -352,7 +352,7 @@ Relevant RFCs: Other language changes ---------------------- -* Removed support for static calls to non-static calls form an incompatible +* Removed support for static calls to non-static methods from an incompatible $this context. In this case $this will not be defined, but the call will be allowed with a deprecation notice. An example: From bb55ac6279090c81f66a7ac3dfc25bc1001db51d Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 27 Oct 2015 13:18:50 +0000 Subject: [PATCH 59/65] Fixed typo in reflection phpt --- ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt b/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt index 900ce21d45..bbe5fdbaec 100644 --- a/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt +++ b/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt @@ -5,7 +5,7 @@ Stefan Koopmanschap TestFest PHP|Tek --SKIPIF-- --FILE-- Date: Wed, 28 Oct 2015 11:21:15 +0800 Subject: [PATCH 60/65] rm duplicate include --- sapi/cgi/cgi_main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 6293470472..63f7dfca6b 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -31,7 +31,6 @@ #include "SAPI.h" #include -#include "php.h" #ifdef PHP_WIN32 # include "win32/time.h" From 83de5364b79979c9da06aa01a5aafca4b7dba8bc Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 7 Nov 2015 23:03:25 -0800 Subject: [PATCH 61/65] manually apply the typo fix in master --- Zend/zend_alloc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 06cda75363..c9d4de43a4 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -1463,9 +1463,9 @@ static void *zend_mm_realloc_heap(zend_mm_heap *heap, void *ptr, size_t size, si size = real_size; #endif #ifdef ZEND_WIN32 - /* On Windows we don't have ability to extend huge block in-place. - * We allocate them with 2MB size granularuty, to avoid many - * reallocatioons whenthey when they are extended by small peaces + /* On Windows we don't have ability to extend huge blocks in-place. + * We allocate them with 2MB size granularity, to avoid many + * reallocations when they are extended by small pieces */ new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); #else @@ -1731,9 +1731,9 @@ static void zend_mm_change_huge_block_size(zend_mm_heap *heap, void *ptr, size_t static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) { #ifdef ZEND_WIN32 - /* On Windows we don't have ability to extend huge block in-place. - * We allocate them with 2MB size granularuty, to avoid many - * reallocatioons whenthey when they are extended by small peaces + /* On Windows we don't have ability to extend huge blocks in-place. + * We allocate them with 2MB size granularity, to avoid many + * reallocations when they are extended by small pieces */ size_t new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE)); #else From 6ff014b31cdb30abeb4999de0030342d0109ed91 Mon Sep 17 00:00:00 2001 From: Caleb Champlin Date: Mon, 2 Nov 2015 21:58:04 +0000 Subject: [PATCH 62/65] Make sure context is set to null to prevent use after free --- main/streams/streams.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main/streams/streams.c b/main/streams/streams.c index 3ad44b07a9..d0f8a44b98 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -84,6 +84,7 @@ fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream); if (stream->ctx) { zend_list_delete(stream->ctx); + stream->ctx = NULL; } return 0; From 12f1cfa86ad1e4c4174893974c0533d77902196b Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 9 Nov 2015 12:02:27 +0800 Subject: [PATCH 63/65] Update NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 8f3ff128b1..606bb045a0 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ PHP NEWS php_stream_copy_to_mem()). (Anatol) . Fixed bug #70863 (Incorect logic to increment_function for proxy objects). (Anatol) + . Fixed bug #70842 (Persistent Stream Segmentation Fault). (Caleb Champlin) - Opcache: . Fixed bug #70843 (Segmentation fault on MacOSX with From 0a1e199682c1f2503cc78f900c55ad15fcf89b1d Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 9 Nov 2015 12:21:45 +0800 Subject: [PATCH 64/65] Fixed bug #70624 opcache.huge_code_pages --- php.ini-production | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php.ini-production b/php.ini-production index 368794f700..cc3ffa096b 100644 --- a/php.ini-production +++ b/php.ini-production @@ -1842,7 +1842,7 @@ ldap.max_links = -1 ; Enables or disables copying of PHP code (text segment) into HUGE PAGES. ; This should improve performance, but requires appropriate OS configuration. -opcache.huge_code_pages=1 +;opcache.huge_code_pages=1 [curl] ; A default value for the CURLOPT_CAINFO option. This is required to be an From d70aa14f2c1617800cbab431db5c2ea021969cc6 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 9 Nov 2015 17:14:15 +0800 Subject: [PATCH 65/65] Fixed bug #70323 (Regression in zend_fetch_debug_backtrace() can cause segfaults) --- NEWS | 2 ++ Zend/zend_builtin_functions.c | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 606bb045a0..f45a930cbc 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,8 @@ PHP NEWS . Fixed bug #70863 (Incorect logic to increment_function for proxy objects). (Anatol) . Fixed bug #70842 (Persistent Stream Segmentation Fault). (Caleb Champlin) + . Fixed bug #70323 (Regression in zend_fetch_debug_backtrace() can cause + segfaults). (Aharvey, Laruence) - Opcache: . Fixed bug #70843 (Segmentation fault on MacOSX with diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 8ffdcaa0bc..6faa57cd99 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -2481,7 +2481,7 @@ ZEND_FUNCTION(debug_print_backtrace) ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit) /* {{{ */ { - zend_execute_data *call, *ptr, *skip; + zend_execute_data *ptr, *skip, *call = NULL; zend_object *object; int lineno, frameno = 0; zend_function *func; @@ -2490,8 +2490,12 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int zend_string *include_filename = NULL; zval stack_frame; - call = NULL; - ptr = EG(current_execute_data); + array_init(return_value); + + if (!(ptr = EG(current_execute_data))) { + return; + } + if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type)) { call = ptr; ptr = ptr->prev_execute_data; @@ -2509,13 +2513,11 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int ptr = ptr->prev_execute_data; } } + if (!call) { + call = ptr; + ptr = ptr->prev_execute_data; + } } - if (!call) { - call = ptr; - ptr = ptr->prev_execute_data; - } - - array_init(return_value); while (ptr && (limit == 0 || frameno < limit)) { frameno++;