Skip to content

Commit f6e5cc3

Browse files
committed
Prevent double-construction of IntlRuleBasedBreakIterator
1 parent d4383be commit f6e5cc3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
3737
size_t rules_len;
3838
zend_bool compiled = 0;
3939
UErrorCode status = U_ZERO_ERROR;
40-
intl_error_reset(NULL);
40+
BREAKITER_METHOD_INIT_VARS;
41+
object = ZEND_THIS;
4142

4243
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b",
4344
&rules, &rules_len, &compiled) == FAILURE) {
4445
RETURN_THROWS();
4546
}
4647

48+
BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK;
49+
if (bio->biter) {
50+
zend_throw_error(NULL, "IntlRuleBasedBreakIterator object is already constructed");
51+
RETURN_THROWS();
52+
}
53+
4754
// instantiation of ICU object
4855
RuleBasedBreakIterator *rbbi;
4956

ext/intl/tests/breakiter___construct_error.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ try {
3535
} catch (IntlException $e) {
3636
print_exception($e);
3737
}
38+
39+
$rbbi = new IntlRuleBasedBreakIterator(".;");
40+
try {
41+
$rbbi->__construct(".;");
42+
} catch (Error $e) {
43+
print_exception($e);
44+
}
3845
?>
3946
--EXPECTF--
4047
Exception: IntlRuleBasedBreakIterator::__construct(): unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d
@@ -46,3 +53,5 @@ Exception: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameter
4653
Exception: IntlRuleBasedBreakIterator::__construct(): Argument #2 ($areCompiled) must be of type bool, array given in %s on line %d
4754

4855
Exception: IntlRuleBasedBreakIterator::__construct(): unable to create instance from compiled rules in %s on line %d
56+
57+
Exception: IntlRuleBasedBreakIterator object is already constructed in %s on line %d

0 commit comments

Comments
 (0)