Skip to content

Commit 9f87a19

Browse files
committed
ext/sockets: drop convert_to_array for multicast leave group settings.
close GH-17371
1 parent 5ba299b commit 9f87a19

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ PHP NEWS
9494
overflows. (David Carlier)
9595
. socket_addrinfo_lookup throws an exception if one or more hints entries
9696
has an index as numeric. (David Carlier)
97+
. socket_set_option with the options MCAST_LEAVE_GROUP/MCAST_LEAVE_SOURCE_GROUP
98+
will throw an exception if its value is not a valid array/object.
99+
(David Carlier)
97100

98101
- Standard:
99102
. Fixed crypt() tests on musl when using --with-external-libcrypt

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ PHP 8.5 UPGRADE NOTES
131131
. socket_addrinfo_lookup throw a TypeError if any of the hints
132132
values cannot be cast to a int and can throw a ValueError if
133133
any of these values overflow.
134+
. socket_set_option with MCAST_LEAVE_GROUP/MCAST_LEAVE_SOURCE_GROUP
135+
options will throw an exception if the value isn't a valid object
136+
or array.
134137

135138
- Zlib:
136139
. The "use_include_path" argument for the

ext/sockets/multicast.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,16 @@ mcast_req_fun: ;
159159
php_sockaddr_storage group = {0};
160160
socklen_t glen;
161161

162-
convert_to_array(arg4);
163-
opt_ht = Z_ARRVAL_P(arg4);
162+
if (Z_TYPE_P(arg4) != IS_ARRAY) {
163+
if (UNEXPECTED(Z_TYPE_P(arg4) != IS_OBJECT)) {
164+
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));
165+
return FAILURE;
166+
} else {
167+
opt_ht = Z_OBJPROP_P(arg4);
168+
}
169+
} else {
170+
opt_ht = Z_ARRVAL_P(arg4);
171+
}
164172

165173
if (php_get_address_from_array(opt_ht, "group", php_sock, &group,
166174
&glen) == FAILURE) {
@@ -194,9 +202,16 @@ mcast_req_fun: ;
194202
source = {0};
195203
socklen_t glen,
196204
slen;
197-
198-
convert_to_array(arg4);
199-
opt_ht = Z_ARRVAL_P(arg4);
205+
if (Z_TYPE_P(arg4) != IS_ARRAY) {
206+
if (UNEXPECTED(Z_TYPE_P(arg4) != IS_OBJECT)) {
207+
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));
208+
return FAILURE;
209+
} else {
210+
opt_ht = Z_OBJPROP_P(arg4);
211+
}
212+
} else {
213+
opt_ht = Z_ARRVAL_P(arg4);
214+
}
200215

201216
if (php_get_address_from_array(opt_ht, "group", php_sock, &group,
202217
&glen) == FAILURE) {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Multicast error
3+
--EXTENSIONS--
4+
sockets
5+
--SKIPIF--
6+
<?php
7+
if (PHP_OS == 'Darwin') die('skip Not for macOS');
8+
?>
9+
--FILE--
10+
<?php
11+
include __DIR__."/mcast_helpers.php.inc";
12+
$domain = AF_INET;
13+
$level = IPPROTO_IP;
14+
$interface = "lo";
15+
$mcastaddr = '224.0.0.23';
16+
$sblock = "127.0.0.1";
17+
18+
$s = socket_create($domain, SOCK_DGRAM, SOL_UDP);
19+
$b = socket_bind($s, '0.0.0.0', 0);
20+
$iwanttoleavenow = true;
21+
22+
try {
23+
socket_set_option($s, $level, MCAST_LEAVE_GROUP, $iwanttoleavenow);
24+
} catch (\TypeError $e) {
25+
echo $e->getMessage(), PHP_EOL;
26+
}
27+
28+
try {
29+
socket_set_option($s, $level, MCAST_LEAVE_SOURCE_GROUP, $iwanttoleavenow);
30+
} catch (\TypeError $e) {
31+
echo $e->getMessage();
32+
}
33+
?>
34+
--EXPECT--
35+
socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_GROUP, true given
36+
socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_SOURCE_GROUP, true given

0 commit comments

Comments
 (0)