Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand Down
23 changes: 23 additions & 0 deletions ext/sockets/tests/socket_bind_invalid_port.phpt
Original file line number Diff line number Diff line change
@@ -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
Loading