]> granicus.if.org Git - php/commitdiff
Fixed bug#48476
authorHannes Magnusson <bjori@php.net>
Tue, 30 Aug 2011 13:41:57 +0000 (13:41 +0000)
committerHannes Magnusson <bjori@php.net>
Tue, 30 Aug 2011 13:41:57 +0000 (13:41 +0000)
ext/date/php_date.c
ext/date/tests/bug48476.phpt [new file with mode: 0644]

index c9a8465592bca5e82af4192f6073fe9fee138e5c..8cb289bef315ba72e580260036094b273c36ec16 100644 (file)
@@ -2045,6 +2045,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();
@@ -2165,6 +2168,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 (file)
index 0000000..4bf9503
--- /dev/null
@@ -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)
+
+