From: Nikita Popov Date: Wed, 26 Aug 2020 08:10:41 +0000 (+0200) Subject: Prevent double-construction of IntlGregorianCalendar X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72eaf509d3e56d3f4310243141f6df1aa4ae3427;p=php Prevent double-construction of IntlGregorianCalendar --- diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp index 84d594185c..64b7539789 100644 --- a/ext/intl/calendar/gregoriancalendar_methods.cpp +++ b/ext/intl/calendar/gregoriancalendar_methods.cpp @@ -85,8 +85,14 @@ static void _php_intlgregcal_constructor_body( } // instantion of ICU object + Calendar_object *co = Z_INTL_CALENDAR_P(return_value); GregorianCalendar *gcal = NULL; + if (co->ucal) { + zend_throw_error(NULL, "IntlGregorianCalendar object is already constructed"); + RETURN_THROWS(); + } + if (variant <= 2) { // From timezone and locale (0 to 2 arguments) TimeZone *tz = timezone_process_timezone_argument(tz_object, NULL, @@ -174,8 +180,7 @@ static void _php_intlgregcal_constructor_body( gcal->adoptTimeZone(tz); } - Calendar_object *co = Z_INTL_CALENDAR_P(return_value); - co->ucal = gcal; + co->ucal = gcal; } U_CFUNC PHP_FUNCTION(intlgregcal_create_instance) diff --git a/ext/intl/tests/gregoriancalendar___construct_error.phpt b/ext/intl/tests/gregoriancalendar___construct_error.phpt index 7e5ce659bf..92a7e5c304 100644 --- a/ext/intl/tests/gregoriancalendar___construct_error.phpt +++ b/ext/intl/tests/gregoriancalendar___construct_error.phpt @@ -33,6 +33,13 @@ try { } catch (TypeError $e) { echo $e->getMessage(), "\n"; } + +$cal = new IntlGregorianCalendar(); +try { + $cal->__construct(); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} ?> --EXPECT-- Too many arguments @@ -40,3 +47,4 @@ Too many arguments No variant with 4 arguments (excluding trailing NULLs) No variant with 4 arguments (excluding trailing NULLs) IntlGregorianCalendar::__construct(): Argument #6 ($second) must be of type int, array given +IntlGregorianCalendar object is already constructed