diff --git a/NEWS b/NEWS index aa558bbe116..864a6b2e189 100644 --- a/NEWS +++ b/NEWS @@ -94,6 +94,9 @@ PHP NEWS overflows. (David Carlier) . socket_addrinfo_lookup throws an exception if one or more hints entries has an index as numeric. (David Carlier) + . socket_set_option with the options MCAST_LEAVE_GROUP/MCAST_LEAVE_SOURCE_GROUP + will throw an exception if its value is not a valid array/object. + (David Carlier) - Standard: . Fixed crypt() tests on musl when using --with-external-libcrypt diff --git a/UPGRADING b/UPGRADING index 8e56a593119..63307556848 100644 --- a/UPGRADING +++ b/UPGRADING @@ -131,6 +131,9 @@ PHP 8.5 UPGRADE NOTES . socket_addrinfo_lookup throw a TypeError if any of the hints values cannot be cast to a int and can throw a ValueError if any of these values overflow. + . socket_set_option with MCAST_LEAVE_GROUP/MCAST_LEAVE_SOURCE_GROUP + options will throw an exception if the value isn't a valid object + or array. - Zlib: . The "use_include_path" argument for the diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c index e258ca3e66e..06bc03e7f20 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 00000000000..0d7630fb279 --- /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