Skip to content

Commit 0fce19a

Browse files
committed
initial fix
1 parent f63be32 commit 0fce19a

4 files changed

Lines changed: 36 additions & 2 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ PHP NEWS
172172
(Weilin Du)
173173
. getenv() and putenv() now raises a ValueError when the first argument
174174
contains null bytes. (Weilin Du)
175+
. strptime() now raises a ValueError when $timestamp or $format contains
176+
null bytes. (Weilin Du)
175177

176178
- Streams:
177179
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ PHP 8.6 UPGRADE NOTES
9595
argument value is passed.
9696
. scandir() now raises a ValueError when an invalid $sorting_order
9797
argument value is passed.
98+
. strptime() now raises a ValueError when the $timestamp or $format
99+
argument contains null bytes.
98100

99101
- Zip:
100102
. ZipArchive::extractTo now raises a TypeError for the

ext/standard/datetime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ PHP_FUNCTION(strptime)
3838
char *unparsed_part;
3939

4040
ZEND_PARSE_PARAMETERS_START(2, 2)
41-
Z_PARAM_STRING(ts, ts_length)
42-
Z_PARAM_STRING(format, format_length)
41+
Z_PARAM_PATH(ts, ts_length)
42+
Z_PARAM_PATH(format, format_length)
4343
ZEND_PARSE_PARAMETERS_END();
4444

4545
memset(&parsed_time, 0, sizeof(parsed_time));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
strptime() rejects null bytes
3+
--SKIPIF--
4+
<?php
5+
if (!function_exists('strptime')) {
6+
die("skip - strptime() function not available in this build");
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
12+
try {
13+
strptime("2024-01-01\0UTC", "%Y-%m-%d");
14+
} catch (ValueError $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
try {
19+
strptime("2024-01-01", "%Y-%m-%d\0");
20+
} catch (ValueError $e) {
21+
echo $e->getMessage(), "\n";
22+
}
23+
24+
?>
25+
--EXPECTF--
26+
Deprecated: Function strptime() is deprecated since 8.2, use date_parse_from_format() (for locale-independent parsing), or IntlDateFormatter::parse() (for locale-dependent parsing) instead in %s on line %d
27+
strptime(): Argument #1 ($timestamp) must not contain any null bytes
28+
29+
Deprecated: Function strptime() is deprecated since 8.2, use date_parse_from_format() (for locale-independent parsing), or IntlDateFormatter::parse() (for locale-dependent parsing) instead in %s on line %d
30+
strptime(): Argument #2 ($format) must not contain any null bytes

0 commit comments

Comments
 (0)