1
0
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:
David Carlier
2024-12-29 14:01:46 +00:00
parent 8120c7988a
commit caafa041d9
4 changed files with 32 additions and 2 deletions

2
NEWS
View File

@@ -84,6 +84,8 @@ PHP NEWS
TCP_REUSPORT_LB_CURDOM, TCP_BBR_ALGORITHM constants.
. socket_create_listen() throws an exception on invalid port value.
(David Carlier)
. socket_bind() throws an exception on invalid port value.
(David Carlier)
- Standard:
. Fixed crypt() tests on musl when using --with-external-libcrypt

View File

@@ -125,8 +125,8 @@ PHP 8.5 UPGRADE NOTES
last_error to EBADF and raises an E_WARNING message.
- Sockets:
. socket_create_listen throws a ValueError if the port is
lower than 0 or greater than 65535.
. socket_create_listen and socket_bind throw a ValueError
if the port is lower than 0 or greater than 65535.
- Zlib:
. The "use_include_path" argument for the

View File

@@ -1288,6 +1288,11 @@ PHP_FUNCTION(socket_bind)
php_sock = Z_SOCKET_P(arg1);
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) {
case AF_UNIX:
{

View 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