Merge branch 'PHP-8.3'

* PHP-8.3:
  Add missing returns in ext/date for PHP 8.3+ (#15735)
This commit is contained in:
Máté Kocsis 2024-09-14 22:15:49 +02:00
commit 274ae05c4e
No known key found for this signature in database
GPG Key ID: FD055E41728BF310
2 changed files with 83 additions and 5 deletions

View File

@ -318,6 +318,7 @@ static void date_throw_uninitialized_error(zend_class_entry *ce)
}
if (ce_ptr->type != ZEND_INTERNAL_CLASS) {
zend_throw_error(date_ce_date_object_error, "Object of type %s not been correctly initialized by calling parent::__construct() in its constructor", ZSTR_VAL(ce->name));
return;
}
zend_throw_error(date_ce_date_object_error, "Object of type %s (inheriting %s) has not been correctly initialized by calling parent::__construct() in its constructor", ZSTR_VAL(ce->name), ZSTR_VAL(ce_ptr->name));
}
@ -4093,6 +4094,7 @@ PHP_METHOD(DateTimeZone, __construct)
if (!timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz), &exception_message)) {
zend_throw_exception_ex(date_ce_date_invalid_timezone_exception, 0, "DateTimeZone::__construct(): %s", exception_message);
efree(exception_message);
RETURN_THROWS();
}
}
/* }}} */
@ -4648,11 +4650,6 @@ PHP_METHOD(DateInterval, __construct)
static void php_date_interval_initialize_from_hash(zval **return_value, php_interval_obj **intobj, HashTable *myht) /* {{{ */
{
/* If ->diff is already set, then we need to free it first */
if ((*intobj)->diff) {
timelib_rel_time_dtor((*intobj)->diff);
}
/* If we have a date_string, use that instead */
zval *date_str = zend_hash_str_find(myht, "date_string", strlen("date_string"));
if (date_str && Z_TYPE_P(date_str) == IS_STRING) {
@ -4667,6 +4664,14 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte
Z_STRVAL_P(date_str),
err->error_messages[0].position,
err->error_messages[0].character ? err->error_messages[0].character : ' ', err->error_messages[0].message);
timelib_time_dtor(time);
timelib_error_container_dtor(err);
return;
}
/* If ->diff is already set, then we need to free it first */
if ((*intobj)->diff) {
timelib_rel_time_dtor((*intobj)->diff);
}
(*intobj)->diff = timelib_rel_time_clone(&time->relative);
@ -4681,6 +4686,11 @@ static void php_date_interval_initialize_from_hash(zval **return_value, php_inte
return;
}
/* If ->diff is already set, then we need to free it first */
if ((*intobj)->diff) {
timelib_rel_time_dtor((*intobj)->diff);
}
/* Set new value */
(*intobj)->diff = timelib_rel_time_ctor();

View File

@ -0,0 +1,68 @@
--TEST--
Test that DateInterval::__unserialize() doesn't modify state in case of a date_string format error
--FILE--
<?php
$interval = new DateInterval("P1Y1DT1H1M");
var_dump($interval);
try {
$interval->__unserialize(
[
"date_string" => "wrong",
]
);
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
var_dump($interval);
?>
--EXPECTF--
object(DateInterval)#%d (%d) {
["y"]=>
int(1)
["m"]=>
int(0)
["d"]=>
int(1)
["h"]=>
int(1)
["i"]=>
int(1)
["s"]=>
int(0)
["f"]=>
float(0)
["invert"]=>
int(0)
["days"]=>
bool(false)
["from_string"]=>
bool(false)
}
Unknown or bad format (wrong) at position 0 (w) while unserializing: The timezone could not be found in the database
object(DateInterval)#%d (%d) {
["y"]=>
int(1)
["m"]=>
int(0)
["d"]=>
int(1)
["h"]=>
int(1)
["i"]=>
int(1)
["s"]=>
int(0)
["f"]=>
float(0)
["invert"]=>
int(0)
["days"]=>
bool(false)
["from_string"]=>
bool(false)
}