From: Hannes Magnusson Date: Tue, 30 Aug 2011 13:41:57 +0000 (+0000) Subject: Fixed bug#48476 X-Git-Tag: php-5.3.9RC1~322 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a84c667e0e753d5d8051957de08fbf3efb08009a;p=php Fixed bug#48476 --- diff --git a/NEWS b/NEWS index c557b615f5..5e012837f9 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,10 @@ PHP NEWS (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) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index f647c7e584..f05f16a867 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2047,6 +2047,9 @@ static zend_object_value date_object_clone_date(zval *this_ptr TSRMLS_DC) 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 @@ static zend_object_value date_object_clone_timezone(zval *this_ptr TSRMLS_DC) 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) { diff --git a/ext/date/tests/bug48476.phpt b/ext/date/tests/bug48476.phpt new file mode 100644 index 0000000000..4bf9503759 --- /dev/null +++ b/ext/date/tests/bug48476.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug#48476 (cloning extended DateTime class without calling parent::__constr crashed PHP) +--FILE-- +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) + +