Re: Re: com php-src: Fixed bug #67118 DateTime constructor crash with invalid data: NEWS ext/date/php_date.c ext/date/tests/bug67118.phpt
| From: | Remi Collet | Date: | Thu, 05 Jun 2014 06:47:22 +0000 |
| Subject: | Re: Re: com php-src: Fixed bug #67118 DateTime constructor crash with invalid data: NEWS ext/date/php_date.c ext/date/tests/bug67118.phpt | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-74751@lists.php.net to get a copy of this message | ||
Same patch with unit test.
$ make test TESTS=ext/date/tests
=====================================================================
Number of tests : 587 561
Tests skipped : 26 ( 4.4%) --------
Tests warned : 0 ( 0.0%) ( 0.0%)
Tests failed : 0 ( 0.0%) ( 0.0%)
Expected fail : 20 ( 3.4%) ( 3.6%)
Tests passed : 541 ( 92.2%) ( 96.4%)
---------------------------------------------------------------------
Time taken : 15 seconds
=====================================================================
diff -up ext/date/php_date.c.old ext/date/php_date.c --- ext/date/php_date.c.old 2014-06-05 07:42:56.431491483 +0200 +++ ext/date/php_date.c 2014-06-05 08:39:07.539879170 +0200 @@ -2582,6 +2582,8 @@ PHPAPI int php_date_initialize(php_date_ 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; } @@ -2730,7 +2732,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()); + //ZVAL_NULL(getThis()); } } zend_restore_error_handling(&error_handling TSRMLS_CC); diff -up ext/date/tests/bug67118_2.phpt.old ext/date/tests/bug67118_2.phpt --- ext/date/tests/bug67118_2.phpt.old 2014-06-05 08:42:49.779769633 +0200 +++ ext/date/tests/bug67118_2.phpt 2014-06-05 08:44:14.172109174 +0200 @@ -0,0 +1,35 @@ +--TEST-- +Regression introduce in fix for Bug #67118 +--INI-- +date.timezone=Europe/Paris +--FILE-- +<?php +class Foo extends DateTime { + public function __construct($time = null) { + $tz = new DateTimeZone('UTC'); + try { + echo "First try\n"; + parent::__construct($time, $tz); + return; + } catch (Exception $e) { + echo "Second try\n"; + parent::__construct($time.'C', $tz); + } + } +} +$date = '12 Sep 2007 15:49:12 UT'; +var_dump(new Foo($date)); +?> +Done +--EXPECTF-- +First try +Second try +object(Foo)#1 (3) { + ["date"]=> + string(26) "2007-09-12 15:49:12.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(3) "UTC" +} +Done \ Pas de fin de ligne à la fin du fichier diff -up ext/date/tests/bug67118.phpt.old ext/date/tests/bug67118.phpt --- ext/date/tests/bug67118.phpt.old 2014-06-05 08:33:49.511601682 +0200 +++ ext/date/tests/bug67118.phpt 2014-06-05 08:41:50.658533651 +0200 @@ -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
diff -up ext/date/php_date.c.old ext/date/php_date.c --- ext/date/php_date.c.old 2014-06-05 07:42:56.431491483 +0200 +++ ext/date/php_date.c 2014-06-05 08:39:07.539879170 +0200 @@ -2582,6 +2582,8 @@ PHPAPI int php_date_initialize(php_date_ 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; } @@ -2730,7 +2732,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()); + //ZVAL_NULL(getThis()); } } zend_restore_error_handling(&error_handling TSRMLS_CC); diff -up ext/date/tests/bug67118_2.phpt.old ext/date/tests/bug67118_2.phpt --- ext/date/tests/bug67118_2.phpt.old 2014-06-05 08:42:49.779769633 +0200 +++ ext/date/tests/bug67118_2.phpt 2014-06-05 08:44:14.172109174 +0200 @@ -0,0 +1,35 @@ +--TEST-- +Regression introduce in fix for Bug #67118 +--INI-- +date.timezone=Europe/Paris +--FILE-- +<?php +class Foo extends DateTime { + public function __construct($time = null) { + $tz = new DateTimeZone('UTC'); + try { + echo "First try\n"; + parent::__construct($time, $tz); + return; + } catch (Exception $e) { + echo "Second try\n"; + parent::__construct($time.'C', $tz); + } + } +} +$date = '12 Sep 2007 15:49:12 UT'; +var_dump(new Foo($date)); +?> +Done +--EXPECTF-- +First try +Second try +object(Foo)#1 (3) { + ["date"]=> + string(26) "2007-09-12 15:49:12.000000" + ["timezone_type"]=> + int(3) + ["timezone"]=> + string(3) "UTC" +} +Done \ Pas de fin de ligne à la fin du fichier diff -up ext/date/tests/bug67118.phpt.old ext/date/tests/bug67118.phpt --- ext/date/tests/bug67118.phpt.old 2014-06-05 08:33:49.511601682 +0200 +++ ext/date/tests/bug67118.phpt 2014-06-05 08:41:50.658533651 +0200 @@ -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