Skip to content

Commit dfd1d7a

Browse files
committed
Fixed bug #76963 (Null-byte injection in createFromFormat)
1 parent e05897f commit dfd1d7a

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

ext/date/php_date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ PHP_FUNCTION(date_create_from_format)
23822382

23832383
ZEND_PARSE_PARAMETERS_START(2, 3)
23842384
Z_PARAM_STRING(format_str, format_str_len)
2385-
Z_PARAM_STRING(time_str, time_str_len)
2385+
Z_PARAM_PATH(time_str, time_str_len)
23862386
Z_PARAM_OPTIONAL
23872387
Z_PARAM_OBJECT_OF_CLASS_OR_NULL(timezone_object, date_ce_timezone)
23882388
ZEND_PARSE_PARAMETERS_END();
@@ -2404,7 +2404,7 @@ PHP_FUNCTION(date_create_immutable_from_format)
24042404

24052405
ZEND_PARSE_PARAMETERS_START(2, 3)
24062406
Z_PARAM_STRING(format_str, format_str_len)
2407-
Z_PARAM_STRING(time_str, time_str_len)
2407+
Z_PARAM_PATH(time_str, time_str_len)
24082408
Z_PARAM_OPTIONAL
24092409
Z_PARAM_OBJECT_OF_CLASS_OR_NULL(timezone_object, date_ce_timezone)
24102410
ZEND_PARSE_PARAMETERS_END();
@@ -2804,7 +2804,7 @@ PHP_FUNCTION(date_parse_from_format)
28042804

28052805
ZEND_PARSE_PARAMETERS_START(2, 2)
28062806
Z_PARAM_STR(format)
2807-
Z_PARAM_STR(date)
2807+
Z_PARAM_PATH_STR(date)
28082808
ZEND_PARSE_PARAMETERS_END();
28092809

28102810
parsed_time = timelib_parse_from_format(ZSTR_VAL(format), ZSTR_VAL(date), ZSTR_LEN(date), &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);

ext/date/tests/bug76963.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #76963 (Null-byte injection in CreateFromFormat and related functions)
3+
--FILE--
4+
<?php
5+
$strings = [
6+
'8/8/2016',
7+
"8/8/2016\0asf",
8+
];
9+
10+
foreach ($strings as $string) {
11+
echo "Covering string: ", htmlspecialchars( $string), "\n";
12+
13+
try {
14+
$d1 = DateTime::createFromFormat('m/d/Y', $string);
15+
} catch (ValueError $v) {
16+
echo $v->getMessage(), "\n";
17+
}
18+
19+
try {
20+
$d2 = DateTimeImmutable::createFromFormat('m/d/Y', $string);
21+
} catch (ValueError $v) {
22+
echo $v->getMessage(), "\n";
23+
}
24+
25+
try {
26+
$d3 = date_parse_from_format('m/d/Y', $string);
27+
} catch (ValueError $v) {
28+
echo $v->getMessage(), "\n";
29+
}
30+
31+
var_dump($d1, $d2, $d3);
32+
}

0 commit comments

Comments
 (0)