8000 Bugfix for #66091: memory leak in DateTime::createFromFormat() and friends by datibbaw · Pull Request #768 · php/php-src · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -2539,11 +2539,7 @@ static void date_object_free_storage_period(void *object TSRMLS_DC)
/* Advanced Interface */
PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC)
{
Z_TYPE_P(object) = IS_OBJECT;
object_init_ex(object, pce);
Z_SET_REFCOUNT_P(object, 1);
Z_UNSET_ISREF_P(object);

return object;
}

Expand Down Expand Up @@ -2651,15 +2647,18 @@ PHP_FUNCTION(date_create)
zval *timezone_object = NULL;
char *time_str = NULL;
int time_str_len = 0;
zval datetime_object;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
RETURN_FALSE;
}

php_date_instantiate(date_ce_date, return_value TSRMLS_CC);
if (!php_date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
php_date_instantiate(date_ce_date, &datetime_object TSRMLS_CC);
if (!php_date_initialize(zend_object_store_get_object(&datetime_object TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
zval_dtor(&datetime_object);
RETURN_FALSE;
}
RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */

Expand All @@ -2671,15 +2670,18 @@ PHP_FUNCTION(date_create_immutable)
zval *timezone_object = NULL;
char *time_str = NULL;
int time_str_len = 0;
zval datetime_object;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
RETURN_FALSE;
}

php_date_instantiate(date_ce_immutable, return_value TSRMLS_CC);
if (!php_date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
php_date_instantiate(date_ce_immutable, &datetime_object TSRMLS_CC);
if (!php_date_initialize(zend_object_store_get_object(&datetime_object TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
zval_dtor(&datetime_object);
RETURN_FALSE;
}
RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */

Expand All @@ -2691,15 +2693,18 @@ PHP_FUNCTION(date_create_from_format)
zval *timezone_object = NULL;
char *time_str = NULL, *format_str = NULL;
int time_str_len = 0, format_str_len = 0;
zval datetime_object;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|O", &format_str, &format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
RETURN_FALSE;
}

php_date_instantiate(date_ce_date, return_value TSRMLS_CC);
if (!php_date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
php_date_instantiate(date_ce_date, &datetime_object TSRMLS_CC);
if (!php_date_initialize(zend_object_store_get_object(&datetime_object TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
zval_dtor(&datetime_object);
RETURN_FALSE;
}
RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */

Expand All @@ -2711,15 +2716,18 @@ PHP_FUNCTION(date_create_immutable_from_format)
zval *timezone_object = NULL;
char *time_str = NULL, *format_str = NULL;
int time_str_len = 0, format_str_len = 0;
zval datetime_object;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|O", &format_str, &format_str_len, &time_str, &time_str_len, &timezone_object, date_ce_timezone) == FAILURE) {
RETURN_FALSE;
}

php_date_instantiate(date_ce_immutable, return_value TSRMLS_CC);
if (!php_date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
php_date_instantiate(date_ce_immutable, &datetime_object TSRMLS_CC);
if (!php_date_initialize(zend_object_store_get_object(&datetime_object TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
zval_dtor(&datetime_object);
RETURN_FALSE;
}
RETVAL_ZVAL(&datetime_object, 0, 0);
}
/* }}} */

Expand Down Expand Up @@ -2789,7 +2797,7 @@ PHP_METHOD(DateTimeImmutable, createFromMutable)
}
/* }}} */

static int php_date_initialize_from_hash(zval **return_value, php_date_obj **dateobj, HashTable *myht TSRMLS_DC)
static int php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myht TSRMLS_DC)
{
zval **z_date = NULL;
zval **z_timezone = NULL;
Expand Down Expand Up @@ -2859,7 +2867,7 @@ PHP_METHOD(DateTime, __set_state)

php_date_instantiate(date_ce_date, return_value TSRMLS_CC);
dateobj = (php_date_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
if (!php_date_initialize_from_hash(&return_value, &dateobj, myht TSRMLS_CC)) {
if (!php_date_initialize_from_hash(&dateobj, myht TSRMLS_CC)) {
php_error(E_ERROR, "Invalid serialization data for DateTime object");
}
}
Expand All @@ -2881,7 +2889,7 @@ PHP_METHOD(DateTimeImmutable, __set_state)

php_date_instantiate(date_ce_immutable, return_value TSRMLS_CC);
dateobj = (php_date_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
if (!php_date_initialize_from_hash(&return_value, &dateobj, myht TSRMLS_CC)) {
if (!php_date_initialize_from_hash(&dateobj, myht TSRMLS_CC)) {
php_error(E_ERROR, "Invalid serialization data for DateTimeImmutable object");
}
}
Expand All @@ -2899,7 +2907,7 @@ PHP_METHOD(DateTime, __wakeup)

myht = Z_OBJPROP_P(object);

if (!php_date_initialize_from_hash(&return_value, &dateobj, myht TSRMLS_CC)) {
if (!php_date_initialize_from_hash(&dateobj, myht TSRMLS_CC)) {
php_error(E_ERROR, "Invalid serialization data for DateTime object");
}
}
Expand Down
8 changes: 4 additions & 4 deletions ext/date/tests/bug51866.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ array(4) {

string(6) "Y-m-d+"
string(19) "2001-11-29 13:20:01"
object(DateTime)#2 (3) {
object(DateTime)#%d (3) {
["date"]=>
string(26) "2001-11-29 %d:%d:%d.%d"
["timezone_type"]=>
Expand All @@ -70,7 +70,7 @@ array(4) {

string(7) "Y-m-d +"
string(19) "2001-11-29 13:20:01"
object(DateTime)#3 (3) {
object(DateTime)#%d (3) {
["date"]=>
string(26) "2001-11-29 %d:%d:%d.%d"
["timezone_type"]=>
Expand All @@ -96,7 +96,7 @@ array(4) {

string(6) "Y-m-d+"
string(10) "2001-11-29"
object(DateTime)#2 (3) {
object(DateTime)#%d (3) {
["date"]=>
string(26) "2001-11-29 %d:%d:%d.%d"
["timezone_type"]=>
Expand Down Expand Up @@ -139,7 +139,7 @@ array(4) {

string(7) "Y-m-d +"
string(11) "2001-11-29 "
object(DateTime)#2 (3) {
object(DateTime)#%d (3) {
["date"]=>
string(26) "2001-11-29 %d:%d:%d.%d"
["timezone_type"]=>
Expand Down
0