mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
ext/intl: Fix memory leak in MessageFormatter::format()
Closes GH-11658
This commit is contained in:
parent
b1b7c61a27
commit
536dbd74fa
3
NEWS
3
NEWS
@ -37,6 +37,9 @@ PHP NEWS
|
||||
- GD:
|
||||
. Fix most of the external libgd test failures. (Michael Orlitzky)
|
||||
|
||||
- Intl:
|
||||
. Fix memory leak in MessageFormatter::format() on failure. (Girgias)
|
||||
|
||||
- MBString:
|
||||
. Fix GH-11300 (license issue: restricted unicode license headers).
|
||||
(nielsdos)
|
||||
|
@ -125,21 +125,27 @@ PHP_FUNCTION( msgfmt_format_message )
|
||||
efree(spattern);
|
||||
}
|
||||
|
||||
if (INTL_DATA_ERROR_CODE( mfo ) == U_PATTERN_SYNTAX_ERROR) {
|
||||
char *msg = NULL;
|
||||
smart_str parse_error_str;
|
||||
parse_error_str = intl_parse_error_to_string( &parse_error );
|
||||
spprintf( &msg, 0, "pattern syntax error (%s)", parse_error_str.s? ZSTR_VAL(parse_error_str.s) : "unknown parser error" );
|
||||
smart_str_free( &parse_error_str );
|
||||
/* Cannot use INTL_METHOD_CHECK_STATUS() as we need to free the message object formatter */
|
||||
if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
|
||||
if (INTL_DATA_ERROR_CODE( mfo ) == U_PATTERN_SYNTAX_ERROR) {
|
||||
char *msg = NULL;
|
||||
smart_str parse_error_str;
|
||||
parse_error_str = intl_parse_error_to_string( &parse_error );
|
||||
spprintf( &msg, 0, "pattern syntax error (%s)", parse_error_str.s? ZSTR_VAL(parse_error_str.s) : "unknown parser error" );
|
||||
smart_str_free( &parse_error_str );
|
||||
|
||||
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( mfo ) );
|
||||
intl_errors_set_custom_msg( INTL_DATA_ERROR_P( mfo ), msg, 1 );
|
||||
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( mfo ) );
|
||||
intl_errors_set_custom_msg( INTL_DATA_ERROR_P( mfo ), msg, 1 );
|
||||
|
||||
efree( msg );
|
||||
efree( msg );
|
||||
} else {
|
||||
intl_errors_set_custom_msg( INTL_DATA_ERROR_P(mfo), "Creating message formatter failed", 0 );
|
||||
}
|
||||
/* Reset custom error message as this is a static method that has no object */
|
||||
intl_errors_reset(INTL_DATA_ERROR_P(mfo));
|
||||
umsg_close(MSG_FORMAT_OBJECT(mfo));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed");
|
||||
}
|
||||
|
||||
msgfmt_do_format(mfo, args, return_value);
|
||||
|
||||
|
15
ext/intl/tests/gh11658.phpt
Normal file
15
ext/intl/tests/gh11658.phpt
Normal file
@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
GitHub #11658 MessageFormatter::format() leaks memory
|
||||
--EXTENSIONS--
|
||||
intl
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
ini_set("intl.error_level", E_WARNING);
|
||||
|
||||
$s = MessageFormatter::formatMessage('en', 'some {wrong.format}', []);
|
||||
var_dump($s);
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: MessageFormatter::formatMessage(): pattern syntax error (parse error at offset 6, after "some {", before or at "wrong.format}") in %s on line %d
|
||||
bool(false)
|
Loading…
Reference in New Issue
Block a user