Skip to content

Commit 72eaf50

Browse files
committed
Prevent double-construction of IntlGregorianCalendar
1 parent f6e5cc3 commit 72eaf50

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

ext/intl/calendar/gregoriancalendar_methods.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,14 @@ static void _php_intlgregcal_constructor_body(
8585
}
8686

8787
// instantion of ICU object
88+
Calendar_object *co = Z_INTL_CALENDAR_P(return_value);
8889
GregorianCalendar *gcal = NULL;
8990

91+
if (co->ucal) {
92+
zend_throw_error(NULL, "IntlGregorianCalendar object is already constructed");
93+
RETURN_THROWS();
94+
}
95+
9096
if (variant <= 2) {
9197
// From timezone and locale (0 to 2 arguments)
9298
TimeZone *tz = timezone_process_timezone_argument(tz_object, NULL,
@@ -174,8 +180,7 @@ static void _php_intlgregcal_constructor_body(
174180
gcal->adoptTimeZone(tz);
175181
}
176182

177-
Calendar_object *co = Z_INTL_CALENDAR_P(return_value);
178-
co->ucal = gcal;
183+
co->ucal = gcal;
179184
}
180185

181186
U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)

ext/intl/tests/gregoriancalendar___construct_error.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ try {
3333
} catch (TypeError $e) {
3434
echo $e->getMessage(), "\n";
3535
}
36+
37+
$cal = new IntlGregorianCalendar();
38+
try {
39+
$cal->__construct();
40+
} catch (Error $e) {
41+
echo $e->getMessage(), "\n";
42+
}
3643
?>
3744
--EXPECT--
3845
Too many arguments
3946
Too many arguments
4047
No variant with 4 arguments (excluding trailing NULLs)
4148
No variant with 4 arguments (excluding trailing NULLs)
4249
IntlGregorianCalendar::__construct(): Argument #6 ($second) must be of type int, array given
50+
IntlGregorianCalendar object is already constructed

0 commit comments

Comments
 (0)