summaryrefslogtreecommitdiff
path: root/ext/intl
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-02-26 15:32:18 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-06-05 14:25:07 +0200
commita31f46421d7bf6f55dd9ac5876b8e2eacf7e0708 (patch)
tree24ffd7c5ae5e321c3994048fdd0fd9f68ae7457c /ext/intl
parent528aa7932a839fc6319979c34aa372805d8dc41c (diff)
downloadphp-git-a31f46421d7bf6f55dd9ac5876b8e2eacf7e0708.tar.gz
Allow exceptions in __toString()
RFC: https://wiki.php.net/rfc/tostring_exceptions And convert some object to string conversion related recoverable fatal errors into Error exceptions. Improve exception safety of internal code performing string conversions.
Diffstat (limited to 'ext/intl')
-rw-r--r--ext/intl/dateformat/dateformat_format_object.cpp4
-rw-r--r--ext/intl/timezone/timezone_class.cpp5
-rw-r--r--ext/intl/timezone/timezone_methods.cpp4
-rw-r--r--ext/intl/transliterator/transliterator_class.c9
-rw-r--r--ext/intl/transliterator/transliterator_methods.c5
5 files changed, 17 insertions, 10 deletions
diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp
index c2429fb592..90e148bca0 100644
--- a/ext/intl/dateformat/dateformat_format_object.cpp
+++ b/ext/intl/dateformat/dateformat_format_object.cpp
@@ -142,7 +142,9 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
}
dateStyle = timeStyle = (DateFormat::EStyle)Z_LVAL_P(format);
} else {
- convert_to_string_ex(format);
+ if (!try_convert_to_string(format)) {
+ return;
+ }
if (Z_STRLEN_P(format) == 0) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_format_object: the format is empty", 0);
diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp
index aabb0f3f55..695cc7d3ea 100644
--- a/ext/intl/timezone/timezone_class.cpp
+++ b/ext/intl/timezone/timezone_class.cpp
@@ -179,7 +179,10 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
UnicodeString id,
gottenId;
UErrorCode status = U_ZERO_ERROR; /* outside_error may be NULL */
- convert_to_string_ex(zv_timezone);
+ if (!try_convert_to_string(zv_timezone)) {
+ zval_ptr_dtor_str(&local_zv_tz);
+ return NULL;
+ }
if (intl_stringFromChar(id, Z_STRVAL_P(zv_timezone), Z_STRLEN_P(zv_timezone),
&status) == FAILURE) {
spprintf(&message, 0, "%s: Time zone identifier given is not a "
diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp
index 3f91db3130..6e1d22324b 100644
--- a/ext/intl/timezone/timezone_methods.cpp
+++ b/ext/intl/timezone/timezone_methods.cpp
@@ -177,7 +177,9 @@ double_offset:
} else if (Z_TYPE_P(arg) == IS_OBJECT || Z_TYPE_P(arg) == IS_STRING) {
zend_long lval;
double dval;
- convert_to_string_ex(arg);
+ if (!try_convert_to_string(arg)) {
+ return;
+ }
switch (is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &lval, &dval, 0)) {
case IS_DOUBLE:
zval_ptr_dtor(arg);
diff --git a/ext/intl/transliterator/transliterator_class.c b/ext/intl/transliterator/transliterator_class.c
index a662dcee7d..a619ed4309 100644
--- a/ext/intl/transliterator/transliterator_class.c
+++ b/ext/intl/transliterator/transliterator_class.c
@@ -189,7 +189,7 @@ err:
}
/* }}} */
-#define TRANSLITERATOR_PROPERTY_HANDLER_PROLOG \
+#define TRANSLITERATOR_PROPERTY_HANDLER_PROLOG(return_fail) \
zval tmp_member; \
if( Z_TYPE_P( member ) != IS_STRING ) \
{ \
@@ -197,6 +197,7 @@ err:
zval_get_string_func(member)); \
member = &tmp_member; \
cache_slot = NULL; \
+ if (EG(exception)) { return_fail; } \
}
#define TRANSLITERATOR_PROPERTY_HANDLER_EPILOG \
@@ -210,7 +211,7 @@ static zval *Transliterator_get_property_ptr_ptr( zval *object, zval *member, in
{
zval *retval;
- TRANSLITERATOR_PROPERTY_HANDLER_PROLOG;
+ TRANSLITERATOR_PROPERTY_HANDLER_PROLOG(return NULL);
if(zend_binary_strcmp( "id", sizeof( "id" ) - 1,
Z_STRVAL_P( member ), Z_STRLEN_P( member ) ) == 0 )
@@ -233,7 +234,7 @@ static zval *Transliterator_read_property( zval *object, zval *member, int type,
{
zval *retval;
- TRANSLITERATOR_PROPERTY_HANDLER_PROLOG;
+ TRANSLITERATOR_PROPERTY_HANDLER_PROLOG(return &EG(uninitialized_zval));
if( ( type != BP_VAR_R && type != BP_VAR_IS ) &&
( zend_binary_strcmp( "id", sizeof( "id" ) - 1,
@@ -258,7 +259,7 @@ static zval *Transliterator_read_property( zval *object, zval *member, int type,
static zval *Transliterator_write_property( zval *object, zval *member, zval *value, void **cache_slot )
{
zend_class_entry *scope;
- TRANSLITERATOR_PROPERTY_HANDLER_PROLOG;
+ TRANSLITERATOR_PROPERTY_HANDLER_PROLOG(return value);
if (EG(fake_scope)) {
scope = EG(fake_scope);
diff --git a/ext/intl/transliterator/transliterator_methods.c b/ext/intl/transliterator/transliterator_methods.c
index 25d0b9a4da..50dd344671 100644
--- a/ext/intl/transliterator/transliterator_methods.c
+++ b/ext/intl/transliterator/transliterator_methods.c
@@ -330,9 +330,8 @@ PHP_FUNCTION( transliterator_transliterate )
else
{ /* not a transliterator object as first argument */
int res;
- if(Z_TYPE_P( arg1 ) != IS_STRING )
- {
- convert_to_string( arg1 );
+ if( !try_convert_to_string( arg1 ) ) {
+ return;
}
object = &tmp_object;
res = create_transliterator( Z_STRVAL_P( arg1 ), Z_STRLEN_P( arg1 ),