From a80db7b52aa134bdc8b984167075ad3059b8531c Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 23 Sep 2023 13:32:53 +0100 Subject: [PATCH] Fix GH-12282: IntlDateFormatter::construct should throw an exception is the locale field has an invalid value. Close GH-12282 --- NEWS | 2 ++ ext/intl/dateformat/dateformat_create.cpp | 5 +++++ ext/intl/tests/gh12282.phpt | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 ext/intl/tests/gh12282.phpt diff --git a/NEWS b/NEWS index d63d288c95a..3349db3c9df 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ PHP NEWS - Intl: . Fixed bug GH-12243 (segfault on IntlDateFormatter::construct). (David Carlier) + . Fixed bug GH-12282 (IntlDateFormatter::construct should throw an exception + on an invalid locale). (David Carlier) - PCRE: . Fixed bug GH-11956 (Backport upstream fix, PCRE regular expressions with diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index 50e0bd75b7e..e14eb4f1a2f 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -111,6 +111,11 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin locale_str = (char *) intl_locale_get_default(); } locale = Locale::createFromName(locale_str); + /* get*Name accessors being set does not preclude being bogus */ + if (locale.isBogus() || strlen(locale.getISO3Language()) == 0) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: invalid locale", 0); + return FAILURE; + } /* process calendar */ if (datefmt_process_calendar_arg(calendar_obj, calendar_long, calendar_is_null, locale, "datefmt_create", diff --git a/ext/intl/tests/gh12282.phpt b/ext/intl/tests/gh12282.phpt new file mode 100644 index 00000000000..62d090ba616 --- /dev/null +++ b/ext/intl/tests/gh12282.phpt @@ -0,0 +1,21 @@ +--TEST-- +GitHub #12282 IntlDateFormatter::locale with invalid value. +--EXTENSIONS-- +intl +--FILE-- +getMessage(); +} +--EXPECT-- +datefmt_create: invalid locale: U_ILLEGAL_ARGUMENT_ERROR