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
8 changes: 7 additions & 1 deletion ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ PHP_FUNCTION(socket_sendto)
#endif
int retval;
size_t buf_len, addr_len;
zend_long len, flags, port;
zend_long len, flags, port = 0;
bool port_is_null = 1;
char *buf, *addr;

Expand All @@ -1586,6 +1586,12 @@ PHP_FUNCTION(socket_sendto)
php_sock = Z_SOCKET_P(arg1);
ENSURE_SOCKET_VALID(php_sock);

if (port < 0 || port > USHRT_MAX) {
zend_argument_value_error(6, "must be between 0 and %u", USHRT_MAX);
RETURN_THROWS();
}


if (len < 0) {
zend_argument_value_error(3, "must be greater than or equal to 0");
RETURN_THROWS();
Expand Down
22 changes: 22 additions & 0 deletions ext/sockets/tests/socket_sendto_invalid_port.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
socket_sendto() with invalid port
--EXTENSIONS--
sockets
--FILE--
<?php
$s_c = socket_create_listen(0);
try {
$s_w = socket_sendto($s_c, "foo", 0, MSG_OOB, '127.0.0.1', 65536);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
$s_w = socket_sendto($s_c, "foo", 0, MSG_OOB, '127.0.0.1', -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
socket_close($s_c);
?>
--EXPECT--
socket_sendto(): Argument #6 ($port) must be between 0 and 65535
socket_sendto(): Argument #6 ($port) must be between 0 and 65535
Loading