]> granicus.if.org Git - php/commitdiff
Prevent double-construction of IntlGregorianCalendar
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 26 Aug 2020 08:10:41 +0000 (10:10 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 26 Aug 2020 08:24:57 +0000 (10:24 +0200)
ext/intl/calendar/gregoriancalendar_methods.cpp
ext/intl/tests/gregoriancalendar___construct_error.phpt

index 84d594185c46fe7b2ad15766c6db5f844cc4b617..64b753978928abd9999b0f70298c9b76c09819e4 100644 (file)
@@ -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)
index 7e5ce659bf68adabbcc6dcaa8a90f34f87b3670b..92a7e5c30436c93f4a5a55c22f1bf709276a6bf2 100644 (file)
@@ -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