Skip to content

Commit 64852b4

Browse files
committed
ext/sockets: multicast on unsupported socket type error change.
From a mere warning to an exception. close GH-19114
1 parent 2039664 commit 64852b4

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
. Fetch larger block sizes and better handle SQL_NO_TOTAL when calling
1515
SQLGetData. (Calvin Buckley, Saki Takamachi)
1616

17+
- Sockets:
18+
. socket_set_option for multicast context throws a ValueError
19+
when the socket family is not of AF_INET/AF_INET6 family. (David Carlier)
20+
1721
- Standard:
1822
. Optimized pack(). (nielsdos, divinity76)
1923
. Fixed bug GH-19070 (setlocale($type, NULL) should not be deprecated).

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ PHP 8.5 UPGRADE NOTES
371371
. socket_create/socket_bind can create AF_PACKET family sockets.
372372
. socket_getsockname gets the interface index and its string
373373
representation with AF_PACKET socket.
374+
. socket_set_option with multicast context throws a ValueError
375+
when the created socket is not of AF_INET/AF_INET6 family.
374376

375377
- Tidy:
376378
. tidy::__construct/parseFile/parseString now throws a ValueError

ext/sockets/sockaddr_conv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, zend_string
137137
}
138138
#endif
139139
else {
140-
php_error_docref(NULL, E_WARNING,
141-
"IP address used in the context of an unexpected type of socket");
140+
zend_value_error("IP address used in the context of an unexpected type of socket");
142141
}
143142
return 0;
144143
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Multicast attempt on unsupported socket type
3+
--EXTENSIONS--
4+
sockets
5+
--SKIPIF--
6+
<?php
7+
if (substr(PHP_OS, 0, 3) == 'WIN') {
8+
die('skip Not for Windows!');
9+
}
10+
?>
11+
--FILE--
12+
<?php
13+
$sock_path = sprintf("/tmp/%s.sock", uniqid());
14+
15+
if (file_exists($sock_path))
16+
die('Temporary socket already exists.');
17+
$sock = socket_create(AF_UNIX, SOCK_DGRAM, 0);
18+
socket_bind($sock, $sock_path);
19+
20+
try {
21+
socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array(
22+
"group" => '127.0.0.1',
23+
"interface" => "lo",
24+
));
25+
} catch (\ValueError $e) {
26+
echo $e->getMessage(), PHP_EOL;
27+
}
28+
?>
29+
--EXPECT--
30+
IP address used in the context of an unexpected type of socket

0 commit comments

Comments
 (0)