Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 85 additions & 80 deletions ext/date/php_date.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ext/date/php_date.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ PHPAPI zend_class_entry *php_date_get_period_ce(void);
#define PHP_DATE_INIT_FORMAT 0x02

PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object);
PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, const char *format, zval *timezone_object, int flags);
PHPAPI bool php_date_initialize(php_date_obj *dateobj, const zend_string *time_str, const char *format, zval *timezone_object, int flags);
PHPAPI void php_date_initialize_from_ts_long(php_date_obj *dateobj, zend_long sec, int usec);
PHPAPI bool php_date_initialize_from_ts_double(php_date_obj *dateobj, double ts);

Expand Down
14 changes: 14 additions & 0 deletions ext/date/tests/22993/dateInterval_create_null_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-22993: DateInterval::createFromDateString() rejects embedded NUL byte
--FILE--
<?php

try {
DateInterval::createFromDateString("foo\0bar");
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECTF--
ValueError: DateInterval::createFromDateString(): Argument #1 ($datetime) must not contain any null bytes
14 changes: 14 additions & 0 deletions ext/date/tests/22993/dateInterval_nul_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-22993: DateInterval error message with embedded NUL byte
--FILE--
<?php

try {
new DateInterval("foo\0bar");
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECTF--
ValueError: DateInterval::__construct(): Argument #1 ($duration) must not contain any null bytes
14 changes: 14 additions & 0 deletions ext/date/tests/22993/dateInterval_unserialize_null_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-22993: DateInterval unserialize() error message with embedded NUL byte
--FILE--
<?php

try {
unserialize('O:12:"DateInterval":2:{s:11:"from_string";b:1;s:11:"date_string";s:7:"foo' . "\0" . 'bar";}');
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECTF--
Error: Unknown or bad format (foo%0bar) at position 0 (f) while unserializing: The timezone could not be found in the database
14 changes: 14 additions & 0 deletions ext/date/tests/22993/datePeriod_create_iso8601_null_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-22993: DatePeriod::createFromISO8601String() rejects embedded NUL byte
--FILE--
<?php

try {
DatePeriod::createFromISO8601String("foo\0bar");
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
ValueError: DatePeriod::createFromISO8601String(): Argument #1 ($specification) must not contain any null bytes
16 changes: 16 additions & 0 deletions ext/date/tests/22993/dateTime_modify_embedded_null.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
GH-22993: DateTime::modify() error message with embedded NUL byte
--FILE--
<?php

$now = new DateTime();

try {
$now->modify("foo\0bar");
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECTF--
DateMalformedStringException: DateTime::modify(): Failed to parse time string (foo%0bar) at position %s
14 changes: 14 additions & 0 deletions ext/date/tests/22993/date_interval_null_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-22993: date_interval_create_from_date_string() rejects embedded NUL byte
--FILE--
<?php

try {
date_interval_create_from_date_string("foo\0bar");
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECTF--
ValueError: date_interval_create_from_date_string(): Argument #1 ($datetime) must not contain any null bytes
10 changes: 10 additions & 0 deletions ext/date/tests/22993/ini_date_timezone_null_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
GH-22993: ini_set() with embedded NUL byte in date.timezone
--FILE--
<?php

ini_set("date.timezone", "foo\0bar");

?>
--EXPECTF--
Warning: ini_set(): Invalid date.timezone value 'foo%0bar', using 'UTC' instead in %s on line %d
14 changes: 14 additions & 0 deletions ext/date/tests/22993/nul-byte-error-message.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-22993: DateTimeImmutable rejects embedded NUL byte
--FILE--
<?php

try {
new DateTimeImmutable("foo\0bar");
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
ValueError: DateTimeImmutable::__construct(): Argument #1 ($datetime) must not contain any null bytes
14 changes: 14 additions & 0 deletions ext/date/tests/22993/timezone_set_null_byte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-22993: date_default_timezone_set() rejects embedded NUL byte
--FILE--
<?php

try {
date_default_timezone_set("foo\0bar");
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
ValueError: date_default_timezone_set(): Argument #1 ($timezoneId) must not contain any null bytes
Loading