Skip to content

Commit b2956e0

Browse files
committed
Close the keyword UEnumeration on Locale::getKeywords failure
uloc_getKeywordValue failure destroyed the result array and returned without uenum_close(). Close the enumeration on that path. The success path already closes it. Audited the other uenum_close site in this file (acceptLanguage). Closes GH-23351
1 parent f49b94e commit b2956e0

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ PHP NEWS
3232
. Fixed Locale::parseLocale() reading past a trailing '-' or '_'.
3333
(iliaal, Xuyang Zhang)
3434
. Fixed grapheme_str_split() treating UBRK_DONE as a byte index. (iliaal)
35+
. Fixed a leak in Locale::getKeywords() when a keyword value cannot be
36+
read. (iliaal)
3537

3638
- Opcache:
3739
. Fixed opcache.protect_memory race under ZTS. (realFlowControl)

‎ext/intl/locale/locale_methods.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ PHP_FUNCTION( locale_get_keywords )
776776
zend_string_efree( kw_value_str );
777777
}
778778
zend_array_destroy(Z_ARR_P(return_value));
779+
uenum_close( e );
779780
RETURN_FALSE;
780781
}
781782

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Locale::getKeywords() closes the keyword enumeration on failure
3+
--EXTENSIONS--
4+
intl
5+
--SKIPIF--
6+
<?php
7+
if (version_compare(INTL_ICU_VERSION, '59.1', '<')) {
8+
die('skip for ICU >= 59.1');
9+
}
10+
?>
11+
--FILE--
12+
<?php
13+
var_dump(Locale::getKeywords('en@foo=bar!'));
14+
var_dump(intl_get_error_code() === U_ILLEGAL_ARGUMENT_ERROR);
15+
?>
16+
--EXPECT--
17+
bool(false)
18+
bool(true)

0 commit comments

Comments
 (0)