Merge branch 'PHP-8.0' into PHP-8.1

This commit is contained in:
Derick Rethans 2022-05-05 15:24:10 +01:00
commit 7670ee4342
2 changed files with 62 additions and 4 deletions

View File

@ -2459,8 +2459,10 @@ PHP_METHOD(DateTime, createFromImmutable)
Z_PARAM_OBJECT_OF_CLASS(datetimeimmutable_object, date_ce_immutable)
ZEND_PARSE_PARAMETERS_END();
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
old_obj = Z_PHPDATE_P(datetimeimmutable_object);
DATE_CHECK_INITIALIZED(old_obj->time, DateTimeImmutable);
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
new_obj = Z_PHPDATE_P(return_value);
new_obj->time = timelib_time_clone(old_obj->time);
@ -2478,8 +2480,10 @@ PHP_METHOD(DateTime, createFromInterface)
Z_PARAM_OBJECT_OF_CLASS(datetimeinterface_object, date_ce_interface)
ZEND_PARSE_PARAMETERS_END();
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
old_obj = Z_PHPDATE_P(datetimeinterface_object);
DATE_CHECK_INITIALIZED(old_obj->time, DateTimeInterface);
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_date, return_value);
new_obj = Z_PHPDATE_P(return_value);
new_obj->time = timelib_time_clone(old_obj->time);
@ -2497,8 +2501,10 @@ PHP_METHOD(DateTimeImmutable, createFromMutable)
Z_PARAM_OBJECT_OF_CLASS(datetime_object, date_ce_date)
ZEND_PARSE_PARAMETERS_END();
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
old_obj = Z_PHPDATE_P(datetime_object);
DATE_CHECK_INITIALIZED(old_obj->time, DateTime);
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
new_obj = Z_PHPDATE_P(return_value);
new_obj->time = timelib_time_clone(old_obj->time);
@ -2516,8 +2522,10 @@ PHP_METHOD(DateTimeImmutable, createFromInterface)
Z_PARAM_OBJECT_OF_CLASS(datetimeinterface_object, date_ce_interface)
ZEND_PARSE_PARAMETERS_END();
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
old_obj = Z_PHPDATE_P(datetimeinterface_object);
DATE_CHECK_INITIALIZED(old_obj->time, DateTimeInterface);
php_date_instantiate(execute_data->This.value.ce ? execute_data->This.value.ce : date_ce_immutable, return_value);
new_obj = Z_PHPDATE_P(return_value);
new_obj->time = timelib_time_clone(old_obj->time);

View File

@ -0,0 +1,50 @@
--TEST--
Bug GH-8471: Segmentation fault when converting immutable and mutable DateTime instances created using reflection
--FILE--
<?php
$reflection = new ReflectionClass('\DateTime');
$mutable = $reflection->newInstanceWithoutConstructor();
try {
$immutable = \DateTimeImmutable::createFromMutable($mutable);
} catch (Throwable $t) {
echo $t->getMessage(), "\n";
}
$reflection = new ReflectionClass('\DateTime');
$mutable = $reflection->newInstanceWithoutConstructor();
try {
$immutable = \DateTimeImmutable::createFromInterface($mutable);
} catch (Throwable $t) {
echo $t->getMessage(), "\n";
}
$reflection = new ReflectionClass('\DateTimeImmutable');
$immutable = $reflection->newInstanceWithoutConstructor();
try {
$mutable = \DateTime::createFromImmutable($immutable);
} catch (Throwable $t) {
echo $t->getMessage(), "\n";
}
$reflection = new ReflectionClass('\DateTimeImmutable');
$immutable = $reflection->newInstanceWithoutConstructor();
try {
$mutable = \DateTime::createFromInterface($immutable);
} catch (Throwable $t) {
echo $t->getMessage(), "\n";
}
?>
--EXPECTF--
The DateTime object has not been correctly initialized by its constructor
The DateTimeInterface object has not been correctly initialized by its constructor
The DateTimeImmutable object has not been correctly initialized by its constructor
The DateTimeInterface object has not been correctly initialized by its constructor