Skip to content

Commit aa21625

Browse files
committed
ext/Intl: Fix IntlListFormatter double construction leak (php#22394)
IntlListFormatter stores a UListFormatter pointer. Calling the constructor again on an already initialized object overwrote the existing pointer and leaked the previous formatter. Follow up to the double construction fixes from phpGH-22386 by rejecting repeated IntlListFormatter::__construct() calls. Closes php#22394
1 parent f0236f1 commit aa21625

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PHP NEWS
1818
fallback locale when a language tag cannot be canonicalized. (Weilin Du)
1919
. Fixed memory leaks when calling Collator::__construct() or
2020
Spoofchecker::__construct() twice. (Weilin Du)
21+
. Fixed memory leak when calling IntlListFormatter::__construct() twice.
22+
(Weilin Du)
2123

2224
- Reflection:
2325
. Fixed bug GH-22324 (Ignore leading namespace separator in

ext/intl/listformatter/listformatter_class.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ PHP_METHOD(IntlListFormatter, __construct)
6767
Z_PARAM_LONG(width)
6868
ZEND_PARSE_PARAMETERS_END();
6969

70+
if (LISTFORMATTER_OBJECT(obj)) {
71+
zend_throw_error(NULL, "IntlListFormatter object is already constructed");
72+
RETURN_THROWS();
73+
}
74+
7075
if(locale_len == 0) {
7176
locale = (char *)intl_locale_get_default();
7277
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
IntlListFormatter double construction should not be allowed
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
$formatter = new IntlListFormatter('en_US');
8+
9+
try {
10+
$formatter->__construct('en_US');
11+
} catch (Error $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
?>
15+
--EXPECT--
16+
IntlListFormatter object is already constructed

0 commit comments

Comments
 (0)