Skip to content

Commit 9ebdb49

Browse files
committed
Fix NULL pointer dereference in intl_datetime_decompose()
1 parent beed61d commit 9ebdb49

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎ext/intl/common/common_date.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,17 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz,
128128
return FAILURE;
129129
}
130130

131+
zval_ptr_dtor(&zfuncname);
131132
datetime = Z_PHPDATE_P(z);
133+
if (!datetime->time) {
134+
spprintf(&message, 0, "%s: the %s object is not properly "
135+
"initialized", func, ZSTR_VAL(Z_OBJCE_P(z)->name));
136+
intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR,
137+
message, 1);
138+
efree(message);
139+
return FAILURE;
140+
}
132141
*millis = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval) + (datetime->time->us / 1000);
133-
zval_ptr_dtor(&zfuncname);
134142
}
135143

136144
if (tz) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
intl_datetime_decompose() rejects uninitialized DateTime subclass overriding getTimestamp()
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
8+
class UninitDateTime extends DateTime {
9+
public function __construct() {}
10+
public function getTimestamp(): int {
11+
return 0;
12+
}
13+
}
14+
15+
$dt = new UninitDateTime();
16+
17+
var_dump(IntlDateFormatter::formatObject($dt));
18+
var_dump(intl_get_error_message());
19+
20+
$fmt = new IntlDateFormatter('en_US', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'UTC');
21+
var_dump($fmt->format($dt));
22+
var_dump($fmt->getErrorMessage());
23+
24+
var_dump(MessageFormatter::formatMessage('en_US', '{0,date,short}', [$dt]));
25+
var_dump(intl_get_error_message());
26+
?>
27+
--EXPECTF--
28+
bool(false)
29+
string(%d) "%sthe UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR"
30+
bool(false)
31+
string(%d) "%sthe UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR"
32+
bool(false)
33+
string(83) "The argument for key '0' cannot be used as a date or time: U_ILLEGAL_ARGUMENT_ERROR"

0 commit comments

Comments
 (0)