ext/sockets: multicast on unsupported socket type error change.

From a mere warning to an exception.

close GH-19114
This commit is contained in:
David Carlier 2025-07-13 07:01:44 +01:00
parent 2039664e47
commit 64852b44b5
No known key found for this signature in database
GPG key ID: 2FB76A8CE6CD2B41
4 changed files with 37 additions and 2 deletions

4
NEWS
View file

@ -14,6 +14,10 @@ PHP NEWS
. Fetch larger block sizes and better handle SQL_NO_TOTAL when calling
SQLGetData. (Calvin Buckley, Saki Takamachi)
- Sockets:
. socket_set_option for multicast context throws a ValueError
when the socket family is not of AF_INET/AF_INET6 family. (David Carlier)
- Standard:
. Optimized pack(). (nielsdos, divinity76)
. Fixed bug GH-19070 (setlocale($type, NULL) should not be deprecated).

View file

@ -371,6 +371,8 @@ PHP 8.5 UPGRADE NOTES
. socket_create/socket_bind can create AF_PACKET family sockets.
. socket_getsockname gets the interface index and its string
representation with AF_PACKET socket.
. socket_set_option with multicast context throws a ValueError
when the created socket is not of AF_INET/AF_INET6 family.
- Tidy:
. tidy::__construct/parseFile/parseString now throws a ValueError

View file

@ -137,8 +137,7 @@ int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, zend_string
}
#endif
else {
php_error_docref(NULL, E_WARNING,
"IP address used in the context of an unexpected type of socket");
zend_value_error("IP address used in the context of an unexpected type of socket");
}
return 0;
}

View file

@ -0,0 +1,30 @@
--TEST--
Multicast attempt on unsupported socket type
--EXTENSIONS--
sockets
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Not for Windows!');
}
?>
--FILE--
<?php
$sock_path = sprintf("/tmp/%s.sock", uniqid());
if (file_exists($sock_path))
die('Temporary socket already exists.');
$sock = socket_create(AF_UNIX, SOCK_DGRAM, 0);
socket_bind($sock, $sock_path);
try {
socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array(
"group" => '127.0.0.1',
"interface" => "lo",
));
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
IP address used in the context of an unexpected type of socket