]> granicus.if.org Git - php/commitdiff
Fixed bug #74053 (Corrupted class entries on shutdown when a destructor spawns anothe...
authorDmitry Stogov <dmitry@zend.com>
Fri, 10 Feb 2017 07:31:43 +0000 (10:31 +0300)
committerDmitry Stogov <dmitry@zend.com>
Fri, 10 Feb 2017 07:31:43 +0000 (10:31 +0300)
Merge branch 'master' of github.com:commercebyte/php-src

* 'master' of github.com:commercebyte/php-src:
  Added EG(flags) - executor global flags EG_FLAGS_IN_SHUTDOWN - is set when PHP is in shutdown state
  newly added zend_object_store.no_reuse is redefined as a global zend_object_store_no_reuse, to avoid alignment issues
  Alignment fix, as per @nikic
  The test scripts bug64720.phpt and bug68652.phpt were relying on the buggy behavior, when PHP returns "Undefined static property" error due to class entry corruption. With my fix for bug 74053, both tests return no errors now, I corrected the EXPECTF accordingly
  Bug Fix: Corrupted class entries on shutdown when a destructor spawns another object (C) 2017 CommerceByte Consulting

1  2 
NEWS
Zend/tests/bug64720.phpt
Zend/tests/bug68652.phpt
Zend/tests/bug74053.phpt
main/main.c

diff --cc NEWS
index aba91c3dec0582b87f109a79de0b5dcbd68e4f37,aba91c3dec0582b87f109a79de0b5dcbd68e4f37..cd3df458c8b81de92b30cf083eeaa9a8c36964fa
--- 1/NEWS
--- 2/NEWS
+++ b/NEWS
@@@ -28,6 -28,6 +28,8 @@@ PH
    . Fixed bug #73973 (assertion error in debug_zval_dump). (andrewnester)
    . Fixed bug #73987 (Method compatibility check looks to original 
      definition and not parent). (pmmaga)
++  . Fixed bug #74053 (Corrupted class entries on shutdown when a destructor
++    spawns another object). (jim at commercebyte dot com)
  
  - BCMath:
    . Fixed bug #46564 (bcmod truncates fractionals). (liborm85)
index 45dee3e8c46b4c7039ff47d6cb68ff153645f373,35b01e6a162909becff596365156cb8984c22c6b..efe3379bd4e21c87c13391f5bc9e414b7cebd463
@@@ -44,9 -44,4 +44,6 @@@ $foo = new Foo()
  $bar = new Bar();
  $bar->test();
  ?>
----EXPECTF--
- Fatal error: Uncaught Error: Access to undeclared static property: Stat::$requests in %sbug64720.php:12
- Stack trace:
- #0 [internal function]: Stat->__destruct()
- #1 {main}
-   thrown in %sbug64720.php on line 12
++OK
++--EXPECT--
++OK
index 8e54af2e3485840942b6cef2028638fe709b4325,f0c9d5e9aa1f0f52a1c9da4ca29bd5ca8c1cf321..de450b102a3ac16f9ba3c61aa767c009bf1dfbfb
@@@ -36,11 -36,4 +36,6 @@@ class Bar 
  
  $foo = new Foo();
  ?>
----EXPECTF--
- Fatal error: Uncaught Error: Access to undeclared static property: Bar::$instance in %sbug68652.php:%d
- Stack trace:
- #0 %s(%d): Bar::getInstance()
- #1 [internal function]: Foo->__destruct()
- #2 {main}
-   thrown in %sbug68652.php on line %d
++OK
++--EXPECT--
++OK
index 0000000000000000000000000000000000000000,e8fc02d387b5e9a263fc2fb9877adb4985a6d7fd..b1936a58e9e26ac5d8e13dd23e3ab7555e2fd991
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,43 +1,43 @@@
 ---EXPECTF--
+ --TEST--
+ Bug #74053 (Corrupted class entries on shutdown when a destructor spawns another object)
+ --FILE--
+ <?php
+ class b {
+     function __destruct() {
+       echo "b::destruct\n";
+     }
+ }
+ class a {
+     static $b;
+     static $new;
+     static $max = 10;
+     function __destruct() {
+       if (self::$max-- <= 0) return;
+       echo "a::destruct\n";
+       self::$b = new b;
+       self::$new[] = new a;
+     }
+ }
+ new a;
+ ?>
++--EXPECT--
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
+ a::destruct
+ b::destruct
diff --cc main/main.c
index a8674a5d11784c3fcc1a5954acb09dbd40dbf4c2,0d847638237fb59c87170929cb2b174c6289ecd3..9e139eff72a54673cba57b8e925207d755661388
@@@ -1798,7 -1798,9 +1798,9 @@@ void php_request_shutdown_for_hook(voi
  void php_request_shutdown(void *dummy)
  {
        zend_bool report_memleaks;
 -      
 +
+       EG(flags) |= EG_FLAGS_IN_SHUTDOWN;
        report_memleaks = PG(report_memleaks);
  
        /* EG(current_execute_data) points into nirvana and therefore cannot be safely accessed