From a890c5beb8327b7fbb2f25347256ef0dc5809750 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 28 Feb 2019 13:50:35 +0000 Subject: [PATCH] Fixed bug #50020 (DateInterval:createDateFromString() silently fails) --- NEWS | 14 ++++--- ext/date/php_date.c | 13 ++++++- ...terval_create_from_date_string_broken.phpt | 10 +++++ ...val_create_from_date_string_nullparam.phpt | 38 ++----------------- 4 files changed, 33 insertions(+), 42 deletions(-) create mode 100644 ext/date/tests/date_interval_create_from_date_string_broken.phpt diff --git a/NEWS b/NEWS index c7faa0b9078..7b2e47330e5 100644 --- a/NEWS +++ b/NEWS @@ -7,11 +7,9 @@ PHP NEWS . Fixed bug #77652 (Anonymous classes can lose their interface information). (Nikita) -- Standard: - . Fixed bug #77664 (Segmentation fault when using undefined constant in - custom wrapper). (Laruence) - . Fixed bug #77669 (Crash in extract() when overwriting extracted array). - (Nikita) +- Date: + . Fixed bug #50020 (DateInterval:createDateFromString() silently fails). + (Derick) - MySQLi: . Fixed bug #77597 (mysqli_fetch_field hangs scripts). (Nikita) @@ -19,6 +17,12 @@ PHP NEWS - sodium: . Fixed bug #77646 (sign_detached() strings not terminated). (Frank) +- Standard: + . Fixed bug #77664 (Segmentation fault when using undefined constant in + custom wrapper). (Laruence) + . Fixed bug #77669 (Crash in extract() when overwriting extracted array). + (Nikita) + 07 Mar 2019, PHP 7.2.16 - Core: diff --git a/ext/date/php_date.c b/ext/date/php_date.c index c8479b5164e..5cc3f794cdf 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4435,12 +4435,21 @@ PHP_FUNCTION(date_interval_create_from_date_string) Z_PARAM_STR(time_str) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - php_date_instantiate(date_ce_interval, return_value); - time = timelib_strtotime(ZSTR_VAL(time_str), ZSTR_LEN(time_str), &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); + + if (err->error_count > 0) { + php_error_docref(NULL, E_WARNING, "Unknown or bad format (%s) at position %d (%c): %s", ZSTR_VAL(time_str), + err->error_messages[0].position, err->error_messages[0].character ? err->error_messages[0].character : ' ', err->error_messages[0].message); + RETVAL_FALSE; + goto cleanup; + } + + php_date_instantiate(date_ce_interval, return_value); diobj = Z_PHPINTERVAL_P(return_value); diobj->diff = timelib_rel_time_clone(&time->relative); diobj->initialized = 1; + +cleanup: timelib_time_dtor(time); timelib_error_container_dtor(err); } diff --git a/ext/date/tests/date_interval_create_from_date_string_broken.phpt b/ext/date/tests/date_interval_create_from_date_string_broken.phpt new file mode 100644 index 00000000000..c065de0f8c1 --- /dev/null +++ b/ext/date/tests/date_interval_create_from_date_string_broken.phpt @@ -0,0 +1,10 @@ +--TEST-- +Test date_interval_create_from_date_string() function : nonsense data +--FILE-- + +--EXPECTF-- +Warning: date_interval_create_from_date_string(): Unknown or bad format (foobar) at position 0 (f): The timezone could not be found in the database in %sdate_interval_create_from_date_string_broken.php on line 2 +bool(false) diff --git a/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt b/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt index bb7bf94ce2d..e03386ad3c4 100644 --- a/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt +++ b/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt @@ -4,41 +4,9 @@ Test date_interval_create_from_date_string() function : null parameter Rodrigo Prado de Jesus --FILE-- --EXPECTF-- -object(DateInterval)#%d (16) { - ["y"]=> - int(0) - ["m"]=> - int(0) - ["d"]=> - int(0) - ["h"]=> - int(0) - ["i"]=> - int(0) - ["s"]=> - int(0) - ["f"]=> - float(0) - ["weekday"]=> - int(0) - ["weekday_behavior"]=> - int(0) - ["first_last_day_of"]=> - int(0) - ["invert"]=> - int(0) - ["days"]=> - int(0) - ["special_type"]=> - int(0) - ["special_amount"]=> - int(0) - ["have_weekday_relative"]=> - int(0) - ["have_special_relative"]=> - int(0) -} +Warning: date_interval_create_from_date_string(): Unknown or bad format () at position 0 ( ): Empty string in %sdate_interval_create_from_date_string_nullparam.php on line 2 +bool(false)