summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2008-07-20 20:58:51 +0000
committerDerick Rethans <derick@php.net>2008-07-20 20:58:51 +0000
commitf8050d525f33958ec397e559344b14c7025480ac (patch)
tree1d318807616cbe430bedc593a7c1f737c9012b50
parent04be84748ff262433356c5fd06a5cd5d4702b900 (diff)
downloadphp-git-f8050d525f33958ec397e559344b14c7025480ac.tar.gz
- MFH: Fixed bug #45562 (Creating instance of DatePeriod crashes).
-rw-r--r--ext/date/php_date.c7
-rw-r--r--ext/date/tests/bug44562.phpt38
2 files changed, 43 insertions, 2 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 008e6fe44b..e37039df36 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -3555,6 +3555,7 @@ PHP_FUNCTION(date_interval_create_from_date_string)
time = timelib_strtotime(time_str, time_str_len, &err, DATE_TIMEZONEDB);
diobj = (php_interval_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
diobj->diff = timelib_rel_time_clone(&time->relative);
+ diobj->initialized = 1;
timelib_time_dtor(time);
timelib_error_container_dtor(err);
}
@@ -3671,7 +3672,7 @@ PHP_METHOD(DatePeriod, __construct)
zval *start, *end = NULL, *interval;
long recurrences = 0, options = 0;
char *isostr = NULL;
- int isostr_len;
+ int isostr_len = 0;
timelib_time *clone;
php_set_error_handling(EH_THROW, NULL TSRMLS_CC);
@@ -3698,7 +3699,9 @@ PHP_METHOD(DatePeriod, __construct)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ISO interval '%s' did not contain an end date or a recurrence count.", isostr);
}
- timelib_update_ts(dpobj->start, NULL);
+ if (dpobj->start) {
+ timelib_update_ts(dpobj->start, NULL);
+ }
if (dpobj->end) {
timelib_update_ts(dpobj->end, NULL);
}
diff --git a/ext/date/tests/bug44562.phpt b/ext/date/tests/bug44562.phpt
new file mode 100644
index 0000000000..89ca7402c4
--- /dev/null
+++ b/ext/date/tests/bug44562.phpt
@@ -0,0 +1,38 @@
+--TEST--
+Bug #44562 (Creating instance of DatePeriod crashes)
+--FILE--
+<?php
+date_default_timezone_set('Europe/Oslo');
+
+try
+{
+ $dp = new DatePeriod('2D');
+}
+catch ( Exception $e )
+{
+ echo $e->getMessage(), "\n";
+}
+
+$begin = new DateTime( "2008-07-20T22:44:53+0200" );
+$interval = DateInterval::createFromDateString( "1 day" );
+
+$dp = new DatePeriod( $begin, $interval, 10 );
+foreach ( $dp as $d )
+{
+ var_dump ($d->format( DATE_ISO8601 ) );
+}
+
+?>
+--EXPECT--
+DatePeriod::__construct(): Unknown or bad format (2D)
+string(24) "2008-07-20T22:44:53+0200"
+string(24) "2008-07-21T22:44:53+0200"
+string(24) "2008-07-22T22:44:53+0200"
+string(24) "2008-07-23T22:44:53+0200"
+string(24) "2008-07-24T22:44:53+0200"
+string(24) "2008-07-25T22:44:53+0200"
+string(24) "2008-07-26T22:44:53+0200"
+string(24) "2008-07-27T22:44:53+0200"
+string(24) "2008-07-28T22:44:53+0200"
+string(24) "2008-07-29T22:44:53+0200"
+string(24) "2008-07-30T22:44:53+0200"