Skip to content

Commit f5d9e7c

Browse files
committed
Fix GH-8364: msgfmt_format $values may not support references
We need to deref any references passed in the `$values` array. While we could handle this in the type switch, doing it right away in the foreach loop makes that more explicit, and also circumvents the missing range checks for integers which are not passed as int or double. Closes GH-8407.
1 parent ff90d42 commit f5d9e7c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ PHP NEWS
1616
. Fixed bug #77023 (FPM cannot shutdown processes). (Jakub Zelenka)
1717
. Fixed comment in kqueue remove callback log message. (David Carlier)
1818

19+
- Intl:
20+
. Fixed bug GH-8364 (msgfmt_format $values may not support references). (cmb)
21+
1922
- MySQLi:
2023
. Fixed bug GH-8267 (MySQLi uses unsupported format specifier on Windows).
2124
(cmb)

ext/intl/msgformat/msgformat_helpers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo,
392392
zend_ulong num_index;
393393

394394
ZEND_HASH_FOREACH_KEY_VAL(args, num_index, str_index, elem) {
395+
ZVAL_DEREF(elem);
395396
Formattable& formattable = fargs[argNum];
396397
UnicodeString& key = farg_names[argNum];
397398
Formattable::Type argType = Formattable::kObject, //unknown

ext/intl/tests/gh8364.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug GH-8364 (msgfmt_format $values may not support references)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("intl")) die("skip intl extension not available");
6+
?>
7+
--FILE--
8+
<?php
9+
$formatter = new MessageFormatter('en', 'translate {0}');
10+
$args = ['string', 'string'];
11+
foreach ($args as &$arg) {
12+
// do nothing;
13+
}
14+
$result = $formatter->format($args);
15+
var_dump($result);
16+
var_dump(intl_get_error_code());
17+
?>
18+
--EXPECT--
19+
string(16) "translate string"
20+
int(0)

0 commit comments

Comments
 (0)