Skip to content

Commit 2dcd821

Browse files
committed
Fixed bug #72963 (Null-byte injection in CreateFromFormat and related functions)
1 parent dfd1d7a commit 2dcd821

File tree

2 files changed

+90
-32
lines changed

2 files changed

+90
-32
lines changed

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 13:52:31.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 13:52:31.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

ext/date/tests/bug76963.phpt

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)