svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/date/php_date.c branches/PHP_5_3/ext/date/tests/bug52808.phpt trunk/ext/date/php_date.c
trunk/ext/date/tests/bug52808.phpt
| From: | Stanislav Malyshev | Date: | Sun, 30 Jan 2011 08:54:53 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/date/php_date.c branches/PHP_5_3/ext/date/tests/bug52808.phpt trunk/ext/date/php_date.c trunk/ext/date/tests/bug52808.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-64453@lists.php.net to get a copy of this message | ||
stas Sun, 30 Jan 2011 08:54:53 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=307846
Log:
Fix bug #52808 (Segfault when specifying interval as two dates)
Bug: http://bugs.php.net/52808 (Assigned) Segfault when
specifying interval as two dates
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
U php/php-src/branches/PHP_5_3/ext/date/php_date.c
A php/php-src/branches/PHP_5_3/ext/date/tests/bug52808.phpt
U php/php-src/trunk/ext/date/php_date.c
A php/php-src/trunk/ext/date/tests/bug52808.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2011-01-30 08:47:50 UTC (rev 307845)
+++ php/php-src/branches/PHP_5_3/NEWS 2011-01-30 08:54:53 UTC (rev 307846)
@@ -38,6 +38,7 @@
no effect. (Derick)
. Fixed bug #53729 (DatePeriod fails to initialize recurrences on 64bit
big-endian systems). (Derick, rein@basefarm.no)
+ . Fixed bug #52808 (Segfault when specifying interval as two dates). (Stas)
. Fixed bug #52738 (Can't use new properties in class extended from
DateInterval). (Stas)
. Fixed bug #52063 (DateTime constructor's second argument doesn't have a
Modified: php/php-src/branches/PHP_5_3/ext/date/php_date.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/php_date.c 2011-01-30 08:47:50 UTC (rev 307845)
+++ php/php-src/branches/PHP_5_3/ext/date/php_date.c 2011-01-30 08:54:53 UTC (rev 307846)
@@ -3461,8 +3461,20 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown or bad format (%s)", format);
retval = FAILURE;
} else {
- *rt = p;
- retval = SUCCESS;
+ if(p) {
+ *rt = p;
+ retval = SUCCESS;
+ } else {
+ if(b && e) {
+ timelib_update_ts(b, NULL);
+ timelib_update_ts(e, NULL);
+ *rt = timelib_diff(b, e);
+ retval = SUCCESS;
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse interval (%s)", format);
+ retval = FAILURE;
+ }
+ }
}
timelib_error_container_dtor(errors);
return retval;
Added: php/php-src/branches/PHP_5_3/ext/date/tests/bug52808.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/tests/bug52808.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/date/tests/bug52808.phpt 2011-01-30 08:54:53 UTC (rev 307846)
@@ -0,0 +1,85 @@
+--TEST--
+Bug #52808 (Segfault when specifying interval as two dates)
+--FILE--
+<?php
+date_default_timezone_set('Europe/Oslo');
+$intervals = array(
+ "2008-05-11T15:30:00Z/2007-03-01T13:00:00Z",
+ "2007-05-11T15:30:00Z/2008-03-01T13:00:00Z",
+ "2007-05-11T15:30:00Z 2008-03-01T13:00:00Z",
+ "2007-05-11T15:30:00Z/",
+ "2007-05-11T15:30:00Z",
+ "2007-05-11T15:30:00Z/:00Z",
+);
+foreach($intervals as $iv) {
+ try
+ {
+ $di = new DateInterval($iv);
+ var_dump($di);
+ }
+ catch ( Exception $e )
+ {
+ echo $e->getMessage(), "\n";
+ }
+}
+echo "==DONE==\n";
+?>
+--EXPECTF--
+object(DateInterval)#%d (8) {
+ ["y"]=>
+ int(1)
+ ["m"]=>
+ int(2)
+ ["d"]=>
+ int(10)
+ ["h"]=>
+ int(2)
+ ["i"]=>
+ int(30)
+ ["s"]=>
+ int(0)
+ ["invert"]=>
+ int(1)
+ ["days"]=>
+ int(437)
+}
+object(DateInterval)#%d (8) {
+ ["y"]=>
+ int(0)
+ ["m"]=>
+ int(9)
+ ["d"]=>
+ int(18)
+ ["h"]=>
+ int(21)
+ ["i"]=>
+ int(30)
+ ["s"]=>
+ int(0)
+ ["invert"]=>
+ int(0)
+ ["days"]=>
+ int(294)
+}
+object(DateInterval)#%d (8) {
+ ["y"]=>
+ int(0)
+ ["m"]=>
+ int(9)
+ ["d"]=>
+ int(18)
+ ["h"]=>
+ int(21)
+ ["i"]=>
+ int(30)
+ ["s"]=>
+ int(0)
+ ["invert"]=>
+ int(0)
+ ["days"]=>
+ int(294)
+}
+DateInterval::__construct(): Failed to parse interval (2007-05-11T15:30:00Z/)
+DateInterval::__construct(): Failed to parse interval (2007-05-11T15:30:00Z)
+DateInterval::__construct(): Unknown or bad format (2007-05-11T15:30:00Z/:00Z)
+==DONE==
Modified: php/php-src/trunk/ext/date/php_date.c
===================================================================
--- php/php-src/trunk/ext/date/php_date.c 2011-01-30 08:47:50 UTC (rev 307845)
+++ php/php-src/trunk/ext/date/php_date.c 2011-01-30 08:54:53 UTC (rev 307846)
@@ -3456,8 +3456,20 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown or bad format (%s)", format);
retval = FAILURE;
} else {
- *rt = p;
- retval = SUCCESS;
+ if(p) {
+ *rt = p;
+ retval = SUCCESS;
+ } else {
+ if(b && e) {
+ timelib_update_ts(b, NULL);
+ timelib_update_ts(e, NULL);
+ *rt = timelib_diff(b, e);
+ retval = SUCCESS;
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse interval (%s)", format);
+ retval = FAILURE;
+ }
+ }
}
timelib_error_container_dtor(errors);
return retval;
Added: php/php-src/trunk/ext/date/tests/bug52808.phpt
===================================================================
--- php/php-src/trunk/ext/date/tests/bug52808.phpt (rev 0)
+++ php/php-src/trunk/ext/date/tests/bug52808.phpt 2011-01-30 08:54:53 UTC (rev 307846)
@@ -0,0 +1,85 @@
+--TEST--
+Bug #52808 (Segfault when specifying interval as two dates)
+--FILE--
+<?php
+date_default_timezone_set('Europe/Oslo');
+$intervals = array(
+ "2008-05-11T15:30:00Z/2007-03-01T13:00:00Z",
+ "2007-05-11T15:30:00Z/2008-03-01T13:00:00Z",
+ "2007-05-11T15:30:00Z 2008-03-01T13:00:00Z",
+ "2007-05-11T15:30:00Z/",
+ "2007-05-11T15:30:00Z",
+ "2007-05-11T15:30:00Z/:00Z",
+);
+foreach($intervals as $iv) {
+ try
+ {
+ $di = new DateInterval($iv);
+ var_dump($di);
+ }
+ catch ( Exception $e )
+ {
+ echo $e->getMessage(), "\n";
+ }
+}
+echo "==DONE==\n";
+?>
+--EXPECTF--
+object(DateInterval)#%d (8) {
+ ["y"]=>
+ int(1)
+ ["m"]=>
+ int(2)
+ ["d"]=>
+ int(10)
+ ["h"]=>
+ int(2)
+ ["i"]=>
+ int(30)
+ ["s"]=>
+ int(0)
+ ["invert"]=>
+ int(1)
+ ["days"]=>
+ int(437)
+}
+object(DateInterval)#%d (8) {
+ ["y"]=>
+ int(0)
+ ["m"]=>
+ int(9)
+ ["d"]=>
+ int(18)
+ ["h"]=>
+ int(21)
+ ["i"]=>
+ int(30)
+ ["s"]=>
+ int(0)
+ ["invert"]=>
+ int(0)
+ ["days"]=>
+ int(294)
+}
+object(DateInterval)#%d (8) {
+ ["y"]=>
+ int(0)
+ ["m"]=>
+ int(9)
+ ["d"]=>
+ int(18)
+ ["h"]=>
+ int(21)
+ ["i"]=>
+ int(30)
+ ["s"]=>
+ int(0)
+ ["invert"]=>
+ int(0)
+ ["days"]=>
+ int(294)
+}
+DateInterval::__construct(): Failed to parse interval (2007-05-11T15:30:00Z/)
+DateInterval::__construct(): Failed to parse interval (2007-05-11T15:30:00Z)
+DateInterval::__construct(): Unknown or bad format (2007-05-11T15:30:00Z/:00Z)
+==DONE==