summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <github@derickrethans.nl>2019-02-28 13:50:58 +0000
committerDerick Rethans <github@derickrethans.nl>2019-02-28 13:50:58 +0000
commit7d001aff03168260c9bfbd53a118f5de2566e264 (patch)
treed224f038c88ae56c65ae08322b88c9bc0edca463
parent19a44ffb7be91344550fa700830b8e62a73031ba (diff)
parenta890c5beb8327b7fbb2f25347256ef0dc5809750 (diff)
downloadphp-git-7d001aff03168260c9bfbd53a118f5de2566e264.tar.gz
Merge branch 'DateIntervalBogusData' into PHP-7.2
-rw-r--r--NEWS14
-rw-r--r--ext/date/php_date.c13
-rw-r--r--ext/date/tests/date_interval_create_from_date_string_broken.phpt10
-rw-r--r--ext/date/tests/date_interval_create_from_date_string_nullparam.phpt38
4 files changed, 33 insertions, 42 deletions
diff --git a/NEWS b/NEWS
index c7faa0b907..7b2e47330e 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 c8479b5164..5cc3f794cd 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 0000000000..c065de0f8c
--- /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--
+<?php
+$i = date_interval_create_from_date_string("foobar");
+var_dump($i);
+?>
+--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 bb7bf94ce2..e03386ad3c 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 <royopa [at] gmail [dot] com>
--FILE--
<?php
-$i = date_interval_create_from_date_string(null); //returns a empty object
+$i = date_interval_create_from_date_string(null);
var_dump($i);
?>
--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)