mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
ext/sockets: socket_bind() check port validity.
range from ephemeral port (0) to max unsigned 16 bits. close GH-17296
This commit is contained in:
2
NEWS
2
NEWS
@@ -84,6 +84,8 @@ PHP NEWS
|
|||||||
TCP_REUSPORT_LB_CURDOM, TCP_BBR_ALGORITHM constants.
|
TCP_REUSPORT_LB_CURDOM, TCP_BBR_ALGORITHM constants.
|
||||||
. socket_create_listen() throws an exception on invalid port value.
|
. socket_create_listen() throws an exception on invalid port value.
|
||||||
(David Carlier)
|
(David Carlier)
|
||||||
|
. socket_bind() throws an exception on invalid port value.
|
||||||
|
(David Carlier)
|
||||||
|
|
||||||
- Standard:
|
- Standard:
|
||||||
. Fixed crypt() tests on musl when using --with-external-libcrypt
|
. Fixed crypt() tests on musl when using --with-external-libcrypt
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ PHP 8.5 UPGRADE NOTES
|
|||||||
last_error to EBADF and raises an E_WARNING message.
|
last_error to EBADF and raises an E_WARNING message.
|
||||||
|
|
||||||
- Sockets:
|
- Sockets:
|
||||||
. socket_create_listen throws a ValueError if the port is
|
. socket_create_listen and socket_bind throw a ValueError
|
||||||
lower than 0 or greater than 65535.
|
if the port is lower than 0 or greater than 65535.
|
||||||
|
|
||||||
- Zlib:
|
- Zlib:
|
||||||
. The "use_include_path" argument for the
|
. The "use_include_path" argument for the
|
||||||
|
|||||||
@@ -1288,6 +1288,11 @@ PHP_FUNCTION(socket_bind)
|
|||||||
php_sock = Z_SOCKET_P(arg1);
|
php_sock = Z_SOCKET_P(arg1);
|
||||||
ENSURE_SOCKET_VALID(php_sock);
|
ENSURE_SOCKET_VALID(php_sock);
|
||||||
|
|
||||||
|
if (port < 0 || port > USHRT_MAX) {
|
||||||
|
zend_argument_value_error(3, "must be between 0 and %u", USHRT_MAX);
|
||||||
|
RETURN_THROWS();
|
||||||
|
}
|
||||||
|
|
||||||
switch(php_sock->type) {
|
switch(php_sock->type) {
|
||||||
case AF_UNIX:
|
case AF_UNIX:
|
||||||
{
|
{
|
||||||
|
|||||||
23
ext/sockets/tests/socket_bind_invalid_port.phpt
Normal file
23
ext/sockets/tests/socket_bind_invalid_port.phpt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
--TEST--
|
||||||
|
socket_bind() with invalid ports.
|
||||||
|
--EXTENSIONS--
|
||||||
|
sockets
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$s_c = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||||
|
|
||||||
|
try {
|
||||||
|
socket_bind($s_c, '0.0.0.0', -1);
|
||||||
|
} catch (\ValueError $e) {
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
socket_bind($s_c, '0.0.0.0', 65536);
|
||||||
|
} catch (\ValueError $e) {
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
socket_bind(): Argument #3 ($port) must be between 0 and 65535
|
||||||
|
socket_bind(): Argument #3 ($port) must be between 0 and 65535
|
||||||
Reference in New Issue
Block a user