Skip to content

Commit a04eccb

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
2 parents 040a37d + 172b734 commit a04eccb

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Core:
66
. Fixed bug GH-8338 (Intel CET is disabled unintentionally). (Chen, Hu)
77

8+
- Date:
9+
. Fixed bug #72963 (Null-byte injection in CreateFromFormat and related
10+
functions). (Derick)
11+
812
- MBString:
913
. mb_detect_encoding recognizes all letters in Czech alphabet (alexdowad)
1014
. mb_detect_encoding recognizes all letters in Hungarian alphabet (alexdowad)

ext/date/php_date.c

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

23802380
ZEND_PARSE_PARAMETERS_START(2, 3)
23812381
Z_PARAM_STRING(format_str, format_str_len)
2382-
Z_PARAM_STRING(time_str, time_str_len)
2382+
Z_PARAM_PATH(time_str, time_str_len)
23832383
Z_PARAM_OPTIONAL
23842384
Z_PARAM_OBJECT_OF_CLASS_OR_NULL(timezone_object, date_ce_timezone)
23852385
ZEND_PARSE_PARAMETERS_END();
@@ -2401,7 +2401,7 @@ PHP_FUNCTION(date_create_immutable_from_format)
24012401

24022402
ZEND_PARSE_PARAMETERS_START(2, 3)
24032403
Z_PARAM_STRING(format_str, format_str_len)
2404-
Z_PARAM_STRING(time_str, time_str_len)
2404+
Z_PARAM_PATH(time_str, time_str_len)
24052405
Z_PARAM_OPTIONAL
24062406
Z_PARAM_OBJECT_OF_CLASS_OR_NULL(timezone_object, date_ce_timezone)
24072407
ZEND_PARSE_PARAMETERS_END();
@@ -2803,7 +2803,7 @@ PHP_FUNCTION(date_parse_from_format)
28032803

28042804
ZEND_PARSE_PARAMETERS_START(2, 2)
28052805
Z_PARAM_STR(format)
2806-
Z_PARAM_STR(date)
2806+
Z_PARAM_PATH_STR(date)
28072807
ZEND_PARSE_PARAMETERS_END();
28082808

28092809
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/bug72963.phpt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
--TEST--
2+
Bug #72963 (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+
$d1 = $d2 = $d3 = NULL;
12+
echo "\nCovering string: ", addslashes($string), "\n\n";
13+
14+
try {
15+
$d1 = DateTime::createFromFormat('!m/d/Y', $string);
16+
} catch (ValueError $v) {
17+
echo $v->getMessage(), "\n";
18+
}
19+
20+
try {
21+
$d2 = DateTimeImmutable::createFromFormat('!m/d/Y', $string);
22+
} catch (ValueError $v) {
23+
echo $v->getMessage(), "\n";
24+
}
25+
26+
try {
27+
$d3 = date_parse_from_format('m/d/Y', $string);
28+
} catch (ValueError $v) {
29+
echo $v->getMessage(), "\n";
30+
}
31+
32+
var_dump($d1, $d2, $d3);
33+
}
34+
?>
35+
--EXPECT--
36+
Covering string: 8/8/2016
37+
38+
object(DateTime)#1 (3) {
39+
["date"]=>
40+
string(26) "2016-08-08 00:00:00.000000"
41+
["timezone_type"]=>
42+
int(3)
43+
["timezone"]=>
44+
string(3) "UTC"
45+
}
46+
object(DateTimeImmutable)#2 (3) {
47+
["date"]=>
48+
string(26) "2016-08-08 00:00:00.000000"
49+
["timezone_type"]=>
50+
int(3)
51+
["timezone"]=>
52+
string(3) "UTC"
53+
}
54+
array(12) {
55+
["year"]=>
56+
int(2016)
57+
["month"]=>
58+
int(8)
59+
["day"]=>
60+
int(8)
61+
["hour"]=>
62+
bool(false)
63+
["minute"]=>
64+
bool(false)
65+
["second"]=>
66+
bool(false)
67+
["fraction"]=>
68+
bool(false)
69+
["warning_count"]=>
70+
int(0)
71+
["warnings"]=>
72+
array(0) {
73+
}
74+
["error_count"]=>
75+
int(0)
76+
["errors"]=>
77+
array(0) {
78+
}
79+
["is_localtime"]=>
80+
bool(false)
81+
}
82+
83+
Covering string: 8/8/2016\0asf
84+
85+
DateTime::createFromFormat(): Argument #2 ($datetime) must not contain any null bytes
86+
DateTimeImmutable::createFromFormat(): Argument #2 ($datetime) must not contain any null bytes
87+
date_parse_from_format(): Argument #2 ($datetime) must not contain any null bytes
88+
NULL
89+
NULL
90+
NULL

0 commit comments

Comments
 (0)