Skip to content

Commit acbe0d2

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/intl: Fix double construction leaks (php#22386)
2 parents b5e2653 + 02f71b6 commit acbe0d2

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ PHP NEWS
4848
for invalid display types. (Weilin Du)
4949
. Fixed Locale::lookup() and locale_lookup() to return NULL instead of the
5050
fallback locale when a language tag cannot be canonicalized. (Weilin Du)
51+
. Fixed memory leaks when calling Collator::__construct() or
52+
Spoofchecker::__construct() twice. (Weilin Du)
5153

5254
- Opcache:
5355
. Fixed bug GH-22265 (Another tailcall vm_interrupt bug). (Levi Morrison)

ext/intl/collator/collator_create.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
3737

3838
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
3939
COLLATOR_METHOD_FETCH_OBJECT;
40+
if (co->ucoll) {
41+
zend_throw_error(NULL, "Collator object is already constructed");
42+
return FAILURE;
43+
}
4044

4145
if(locale_len == 0) {
4246
locale = (char *)intl_locale_get_default();

ext/intl/spoofchecker/spoofchecker_create.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ PHP_METHOD(Spoofchecker, __construct)
3131
ZEND_PARSE_PARAMETERS_NONE();
3232

3333
SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK;
34+
if (co->uspoof) {
35+
zend_throw_error(NULL, "Spoofchecker object is already constructed");
36+
RETURN_THROWS();
37+
}
38+
39+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
3440

3541
co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
3642
if (U_FAILURE(INTL_DATA_ERROR_CODE(co))) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Collator double construction should not be allowed
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
$collator = new Collator('en_US');
8+
9+
try {
10+
$collator->__construct('en_US');
11+
} catch (Error $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
?>
15+
--EXPECT--
16+
Collator object is already constructed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Spoofchecker double construction should not be allowed
3+
--EXTENSIONS--
4+
intl
5+
--SKIPIF--
6+
<?php if (!class_exists("Spoofchecker")) print "skip"; ?>
7+
--FILE--
8+
<?php
9+
$checker = new Spoofchecker();
10+
11+
try {
12+
$checker->__construct();
13+
} catch (Error $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
?>
17+
--EXPECT--
18+
Spoofchecker object is already constructed

0 commit comments

Comments
 (0)