Skip to content

Commit 456d602

Browse files
committed
ext/sockets: drop convert_to_array for multicast leave group settings.
1 parent e4ad271 commit 456d602

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

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)