Skip to content

Commit 3c328f0

Browse files
committed
Fix bug #67251 - date_parse_from_format out-of-bounds read
Conflicts: ext/date/lib/parse_date.c ext/date/lib/parse_date.re
1 parent d780c2a commit 3c328f0

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

ext/date/lib/parse_date.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -25121,7 +25121,11 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
2512125121
break;
2512225122

2512325123
case '\\': /* escaped char */
25124-
*fptr++;
25124+
if(!fptr[1]) {
25125+
add_pbf_error(s, "Escaped character expected", string, begin);
25126+
break;
25127+
}
25128+
fptr++;
2512525129
if (*ptr == *fptr) {
2512625130
++ptr;
2512725131
} else {

ext/date/lib/parse_date.re

+5-1
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,11 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
21282128
break;
21292129

21302130
case '\\': /* escaped char */
2131-
*fptr++;
2131+
if(!fptr[1]) {
2132+
add_pbf_error(s, "Escaped character expected", string, begin);
2133+
break;
2134+
}
2135+
fptr++;
21322136
if (*ptr == *fptr) {
21332137
++ptr;
21342138
} else {

ext/date/tests/bug67251.phpt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug #67251 (date_parse_from_format out-of-bounds read)
3+
--INI--
4+
date.timezone=Europe/Berlin
5+
--FILE--
6+
<?php
7+
var_dump(date_parse_from_format("\\","AAAABBBB"));
8+
--EXPECT--
9+
array(12) {
10+
["year"]=>
11+
bool(false)
12+
["month"]=>
13+
bool(false)
14+
["day"]=>
15+
bool(false)
16+
["hour"]=>
17+
bool(false)
18+
["minute"]=>
19+
bool(false)
20+
["second"]=>
21+
bool(false)
22+
["fraction"]=>
23+
bool(false)
24+
["warning_count"]=>
25+
int(0)
26+
["warnings"]=>
27+
array(0) {
28+
}
29+
["error_count"]=>
30+
int(2)
31+
["errors"]=>
32+
array(1) {
33+
[0]=>
34+
string(13) "Trailing data"
35+
}
36+
["is_localtime"]=>
37+
bool(false)
38+
}

0 commit comments

Comments
 (0)