diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c index e258ca3e66e96..06bc03e7f209a 100644 --- a/ext/sockets/multicast.c +++ b/ext/sockets/multicast.c @@ -159,8 +159,16 @@ mcast_req_fun: ; php_sockaddr_storage group = {0}; socklen_t glen; - convert_to_array(arg4); - opt_ht = Z_ARRVAL_P(arg4); + if (Z_TYPE_P(arg4) != IS_ARRAY) { + if (UNEXPECTED(Z_TYPE_P(arg4) != IS_OBJECT)) { + zend_argument_type_error(4, "must be of type array when argument #3 ($option) is MCAST_LEAVE_GROUP, %s given", zend_zval_value_name(arg4)); + return FAILURE; + } else { + opt_ht = Z_OBJPROP_P(arg4); + } + } else { + opt_ht = Z_ARRVAL_P(arg4); + } if (php_get_address_from_array(opt_ht, "group", php_sock, &group, &glen) == FAILURE) { @@ -194,9 +202,16 @@ mcast_req_fun: ; source = {0}; socklen_t glen, slen; - - convert_to_array(arg4); - opt_ht = Z_ARRVAL_P(arg4); + if (Z_TYPE_P(arg4) != IS_ARRAY) { + if (UNEXPECTED(Z_TYPE_P(arg4) != IS_OBJECT)) { + zend_argument_type_error(4, "must be of type array when argument #3 ($option) is MCAST_LEAVE_SOURCE_GROUP, %s given", zend_zval_value_name(arg4)); + return FAILURE; + } else { + opt_ht = Z_OBJPROP_P(arg4); + } + } else { + opt_ht = Z_ARRVAL_P(arg4); + } if (php_get_address_from_array(opt_ht, "group", php_sock, &group, &glen) == FAILURE) { diff --git a/ext/sockets/tests/socket_set_option_mcast_error.phpt b/ext/sockets/tests/socket_set_option_mcast_error.phpt new file mode 100644 index 0000000000000..0d7630fb279cb --- /dev/null +++ b/ext/sockets/tests/socket_set_option_mcast_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Multicast error +--EXTENSIONS-- +sockets +--SKIPIF-- + +--FILE-- +getMessage(), PHP_EOL; +} + +try { + socket_set_option($s, $level, MCAST_LEAVE_SOURCE_GROUP, $iwanttoleavenow); +} catch (\TypeError $e) { + echo $e->getMessage(); +} +?> +--EXPECT-- +socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_GROUP, true given +socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_SOURCE_GROUP, true given