Skip to content

Commit fd718e7

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/intl: Fix double construction leaks (php#22386)
2 parents 9a6aadf + acbe0d2 commit fd718e7

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

ext/intl/collator/collator_create.cpp

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

4545
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
4646
COLLATOR_METHOD_FETCH_OBJECT;
47+
if (co->ucoll) {
48+
zend_throw_error(NULL, "Collator object is already constructed");
49+
return FAILURE;
50+
}
4751

4852
if(locale_len == 0) {
4953
locale = (char *)intl_locale_get_default();

ext/intl/spoofchecker/spoofchecker_create.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ U_CFUNC PHP_METHOD(Spoofchecker, __construct)
3838
ZEND_PARSE_PARAMETERS_NONE();
3939

4040
SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK;
41+
if (co->uspoof) {
42+
zend_throw_error(NULL, "Spoofchecker object is already constructed");
43+
RETURN_THROWS();
44+
}
45+
46+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
4147

4248
co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
4349
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)