From 456d602c7820e72f205a797aaed337d046794275 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 5 Jan 2025 21:29:21 +0000 Subject: [PATCH] ext/sockets: drop convert_to_array for multicast leave group settings. --- ext/sockets/multicast.c | 25 ++++++++++--- .../tests/socket_set_option_mcast_error.phpt | 36 +++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 ext/sockets/tests/socket_set_option_mcast_error.phpt diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c index e258ca3e66e9..06bc03e7f209 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 000000000000..0d7630fb279c --- /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