From 1fe9f1e4f572d7b4d5a3872f41ea61e71fb563bf Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 5 Jun 2014 13:39:46 +0200 Subject: [PATCH 1/3] Fix regression introduce in fix for bug #67118 The fix was correct but break some code (at least in Horde) This is a temporary workaround to fix regressioni in 5.4, 5.5 and 5.6 This make php_date_initialize more consistent - on success return 1 + time initiliazed - on failure return 0 + time = zero which is check by DATE_CHECK_INITIALIZED by later method call Will restore consistency with other date classes in master. --- ext/date/php_date.c | 6 +++--- ext/date/tests/bug67118.phpt | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index a2bf001b7db..595b0b040b9 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2441,6 +2441,8 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message); } if (err && err->error_count) { + timelib_time_dtor(dateobj->time); + dateobj->time = 0; return 0; } @@ -2548,9 +2550,7 @@ PHP_METHOD(DateTime, __construct) zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC); if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { - if (!php_date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC)) { - ZVAL_NULL(getThis()); - } + php_date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC); } zend_restore_error_handling(&error_handling TSRMLS_CC); } diff --git a/ext/date/tests/bug67118.phpt b/ext/date/tests/bug67118.phpt index 6371757647d..973b4eb8d52 100644 --- a/ext/date/tests/bug67118.phpt +++ b/ext/date/tests/bug67118.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #67118 php-cgi crashes regularly on IIS 7 +Bug #67118 crashes in DateTime when this used after failed __construct --INI-- date.timezone=Europe/Berlin --FILE-- @@ -11,17 +11,17 @@ class mydt extends datetime if (!empty($tz) && !is_object($tz)) { $tz = new DateTimeZone($tz); } - - @parent::__construct($time, $tz); + try { + @parent::__construct($time, $tz); + } catch (Exception $e) { + echo "Bad date" . $this->format("Y") . "\n"; + } } }; new mydt("Funktionsansvarig rÄdgivning och juridik", "UTC"); +?> --EXPECTF-- -Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (Funktionsansvarig rÄdgivning och juridik) at position 0 (F): The timezone could not be found in the database' in %sbug67118.php:%d -Stack trace: -#0 %sbug67118.php(%d): DateTime->__construct('Funktionsansvar...', Object(DateTimeZone)) -#1 %sbug67118.php(%d): mydt->__construct('Funktionsansvar...', 'UTC') -#2 {main} - thrown in %sbug67118.php on line %d +Warning: DateTime::format(): The DateTime object has not been correctly initialized by its constructor in %sbug67118.php on line %d +Bad date From 3f47368738fe9123fb1b0a5d543ac7607295951d Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 5 Jun 2014 13:45:25 +0200 Subject: [PATCH 2/3] NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 32a56d0853f..66cb748d2ae 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ PHP NEWS - Date: . Fixed bug #67308 (Serialize of DateTime truncates fractions of second). (Adam) + . Fixed regression in fix for bug #67118 (constructor can't be called twice). + (Remi) - Fileinfo: . Fixed bug #67326 (fileinfo: cdf_read_short_sector insufficient boundary check). From c61c24ad79b2e1a905d405c2f832bfbe20e42133 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 5 Jun 2014 13:46:13 +0200 Subject: [PATCH 3/3] NEWS --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index ff8c6cb3eae..44280cce645 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,9 @@ PHP NEWS - Date: . Fixed bug #67308 (Serialize of DateTime truncates fractions of second). (Adam) + . Fixed regression in fix for bug #67118 (constructor can't be called twice). + (Remi) + - Fileinfo: . Fixed bug #67326 (fileinfo: cdf_read_short_sector insufficient boundary check).