From e1c4a0ae512c3059ff396b7450dfd4bac44ea289 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 27 Jul 2025 12:20:21 +0100 Subject: [PATCH] Fixed GH-19261: msgfmt_parse_message leaks on message format failure. close GH-19262 --- NEWS | 4 ++++ ext/intl/msgformat/msgformat_parse.c | 3 ++- ext/intl/tests/gh19261.phpt | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 ext/intl/tests/gh19261.phpt diff --git a/NEWS b/NEWS index 9f714c37942..b4cc8d8429f 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ PHP NEWS - Hash: . Fix crash on clone failure. (nielsdos) +- Intl: + . Fixed GH-19261: msgfmt_parse_message leaks on message creation failure. + (David Carlier) + - LDAP: . Fixed bug GH-18529 (additional inheriting of TLS int options). (Jakub Zelenka) diff --git a/ext/intl/msgformat/msgformat_parse.c b/ext/intl/msgformat/msgformat_parse.c index baa6dfcce74..31441c92373 100644 --- a/ext/intl/msgformat/msgformat_parse.c +++ b/ext/intl/msgformat/msgformat_parse.c @@ -127,10 +127,11 @@ PHP_FUNCTION( msgfmt_parse_message ) if(spattern && spattern_len) { efree(spattern); } - INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed"); + INTL_METHOD_CHECK_STATUS_OR_GOTO(mfo, "Creating message formatter failed", clean); msgfmt_do_parse(mfo, source, src_len, return_value); +clean: /* drop the temporary formatter */ msgformat_data_free(&mfo->mf_data); } diff --git a/ext/intl/tests/gh19261.phpt b/ext/intl/tests/gh19261.phpt new file mode 100644 index 00000000000..3f281919a95 --- /dev/null +++ b/ext/intl/tests/gh19261.phpt @@ -0,0 +1,28 @@ +--TEST-- +MessageFormatter::parseMessage() with invalid locale +--EXTENSIONS-- +intl +--CREDITS-- +girgias@php.net +--FILE-- + +--EXPECT-- +bool(false) +string(59) "Creating message formatter failed: U_ILLEGAL_ARGUMENT_ERROR" +bool(false) +string(59) "Creating message formatter failed: U_ILLEGAL_ARGUMENT_ERROR"