svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/date/php_date.c branches/PHP_5_3/ext/date/tests/bug48476.phpt
branches/PHP_5_4/ext/date/php_date.c branches/PHP_5_4/ext/date/tests/bug48476.phpt trunk/ext/date/php_date.c trunk/ext/date/tests/bug48476.phpt
| From: | Hannes Magnusson | Date: | Tue, 30 Aug 2011 13:41:57 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/date/php_date.c branches/PHP_5_3/ext/date/tests/bug48476.phpt branches/PHP_5_4/ext/date/php_date.c branches/PHP_5_4/ext/date/tests/bug48476.phpt trunk/ext/date/php_date.c trunk/ext/date/tests/bug48476.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-66033@lists.php.net to get a copy of this message | ||
bjori Tue, 30 Aug 2011 13:41:57 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=315779
Log:
Fixed bug#48476
Bug: https://bugs.php.net/48476 (Assigned) cloning extended
DateTime class without calling parent::__constr crashed PHP
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
U php/php-src/branches/PHP_5_3/ext/date/php_date.c
A php/php-src/branches/PHP_5_3/ext/date/tests/bug48476.phpt
U php/php-src/branches/PHP_5_4/ext/date/php_date.c
A php/php-src/branches/PHP_5_4/ext/date/tests/bug48476.phpt
U php/php-src/trunk/ext/date/php_date.c
A php/php-src/trunk/ext/date/tests/bug48476.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2011-08-30 13:05:35 UTC (rev 315778)
+++ php/php-src/branches/PHP_5_3/NEWS 2011-08-30 13:41:57 UTC (rev 315779)
@@ -7,6 +7,10 @@
(virsacer at web dot de, Pierre)
. Fixed bug #55366: keys lost when using substr_replace an array (arpad)
+- DateTime:
+ . Fixed bug #48476 (cloning extended DateTime class without calling
+ parent::__constr crashed PHP). (Hannes)
+
- Phar:
. Fixed bug#52013 (Unable to decompress files in a compressed phar). (Hannes)
. Fixed bug#53872 (internal corruption of phar). (Hannes)
Modified: php/php-src/branches/PHP_5_3/ext/date/php_date.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/php_date.c 2011-08-30 13:05:35 UTC (rev 315778)
+++ php/php-src/branches/PHP_5_3/ext/date/php_date.c 2011-08-30 13:41:57 UTC (rev 315779)
@@ -2047,6 +2047,9 @@
zend_object_value new_ov = date_object_new_date_ex(old_obj->std.ce, &new_obj TSRMLS_CC);
zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ if (!old_obj->time) {
+ return new_ov;
+ }
/* this should probably moved to a new
timelib_time *timelime_time_clone(timelib_time
*) */
new_obj->time = timelib_time_ctor();
@@ -2168,6 +2171,10 @@
zend_object_value new_ov = date_object_new_timezone_ex(old_obj->std.ce, &new_obj
TSRMLS_CC);
zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ if (!old_obj->initialized) {
+ return new_ov;
+ }
+
new_obj->type = old_obj->type;
new_obj->initialized = 1;
switch (new_obj->type) {
Added: php/php-src/branches/PHP_5_3/ext/date/tests/bug48476.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/tests/bug48476.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/date/tests/bug48476.phpt 2011-08-30 13:41:57 UTC (rev 315779)
@@ -0,0 +1,33 @@
+--TEST--
+Bug#48476 (cloning extended DateTime class without calling parent::__constr crashed PHP)
+--FILE--
+<?php
+class MyDateTime extends DateTime {
+ public function __construct() { }
+}
+class MyDateTimeZone extends DateTimeZone {
+ public function __construct() { }
+}
+
+$o = new MyDateTime;
+var_dump($o->format("d"));
+$x = clone $o;
+
+var_dump($x->format("d"));
+
+clone $o;
+
+
+var_dump(timezone_location_get(clone new MyDateTimezone));
+?>
+--EXPECTF--
+Warning: DateTime::format(): The DateTime object has not been correctly initialized by its
constructor in %sbug48476.php on line 10
+bool(false)
+
+Warning: DateTime::format(): The DateTime object has not been correctly initialized by its
constructor in %sbug48476.php on line 13
+bool(false)
+
+Warning: timezone_location_get(): The DateTimeZone object has not been correctly initialized by its
constructor in %sbug48476.php on line 18
+bool(false)
+
+
Modified: php/php-src/branches/PHP_5_4/ext/date/php_date.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/date/php_date.c 2011-08-30 13:05:35 UTC (rev 315778)
+++ php/php-src/branches/PHP_5_4/ext/date/php_date.c 2011-08-30 13:41:57 UTC (rev 315779)
@@ -2045,6 +2045,9 @@
zend_object_value new_ov = date_object_new_date_ex(old_obj->std.ce, &new_obj TSRMLS_CC);
zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ if (!old_obj->time) {
+ return new_ov;
+ }
/* this should probably moved to a new timelib_time *timelime_time_clone(timelib_time
*) */
new_obj->time = timelib_time_ctor();
@@ -2165,6 +2168,10 @@
zend_object_value new_ov = date_object_new_timezone_ex(old_obj->std.ce, &new_obj
TSRMLS_CC);
zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ if (!old_obj->initialized) {
+ return new_ov;
+ }
+
new_obj->type = old_obj->type;
new_obj->initialized = 1;
switch (new_obj->type) {
Added: php/php-src/branches/PHP_5_4/ext/date/tests/bug48476.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/ext/date/tests/bug48476.phpt (rev 0)
+++ php/php-src/branches/PHP_5_4/ext/date/tests/bug48476.phpt 2011-08-30 13:41:57 UTC (rev 315779)
@@ -0,0 +1,33 @@
+--TEST--
+Bug#48476 (cloning extended DateTime class without calling parent::__constr crashed PHP)
+--FILE--
+<?php
+class MyDateTime extends DateTime {
+ public function __construct() { }
+}
+class MyDateTimeZone extends DateTimeZone {
+ public function __construct() { }
+}
+
+$o = new MyDateTime;
+var_dump($o->format("d"));
+$x = clone $o;
+
+var_dump($x->format("d"));
+
+clone $o;
+
+
+var_dump(timezone_location_get(clone new MyDateTimezone));
+?>
+--EXPECTF--
+Warning: DateTime::format(): The DateTime object has not been correctly initialized by its
constructor in %sbug48476.php on line 10
+bool(false)
+
+Warning: DateTime::format(): The DateTime object has not been correctly initialized by its
constructor in %sbug48476.php on line 13
+bool(false)
+
+Warning: timezone_location_get(): The DateTimeZone object has not been correctly initialized by its
constructor in %sbug48476.php on line 18
+bool(false)
+
+
Modified: php/php-src/trunk/ext/date/php_date.c
===================================================================
--- php/php-src/trunk/ext/date/php_date.c 2011-08-30 13:05:35 UTC (rev 315778)
+++ php/php-src/trunk/ext/date/php_date.c 2011-08-30 13:41:57 UTC (rev 315779)
@@ -2045,6 +2045,9 @@
zend_object_value new_ov = date_object_new_date_ex(old_obj->std.ce, &new_obj TSRMLS_CC);
zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ if (!old_obj->time) {
+ return new_ov;
+ }
/* this should probably moved to a new timelib_time *timelime_time_clone(timelib_time
*) */
new_obj->time = timelib_time_ctor();
@@ -2165,6 +2168,10 @@
zend_object_value new_ov = date_object_new_timezone_ex(old_obj->std.ce, &new_obj
TSRMLS_CC);
zend_objects_clone_members(&new_obj->std, new_ov, &old_obj->std,
Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+ if (!old_obj->initialized) {
+ return new_ov;
+ }
+
new_obj->type = old_obj->type;
new_obj->initialized = 1;
switch (new_obj->type) {
Added: php/php-src/trunk/ext/date/tests/bug48476.phpt
===================================================================
--- php/php-src/trunk/ext/date/tests/bug48476.phpt (rev 0)
+++ php/php-src/trunk/ext/date/tests/bug48476.phpt 2011-08-30 13:41:57 UTC (rev 315779)
@@ -0,0 +1,33 @@
+--TEST--
+Bug#48476 (cloning extended DateTime class without calling parent::__constr crashed PHP)
+--FILE--
+<?php
+class MyDateTime extends DateTime {
+ public function __construct() { }
+}
+class MyDateTimeZone extends DateTimeZone {
+ public function __construct() { }
+}
+
+$o = new MyDateTime;
+var_dump($o->format("d"));
+$x = clone $o;
+
+var_dump($x->format("d"));
+
+clone $o;
+
+
+var_dump(timezone_location_get(clone new MyDateTimezone));
+?>
+--EXPECTF--
+Warning: DateTime::format(): The DateTime object has not been correctly initialized by its
constructor in %sbug48476.php on line 10
+bool(false)
+
+Warning: DateTime::format(): The DateTime object has not been correctly initialized by its
constructor in %sbug48476.php on line 13
+bool(false)
+
+Warning: timezone_location_get(): The DateTimeZone object has not been correctly initialized by its
constructor in %sbug48476.php on line 18
+bool(false)
+
+