Skip to content
Draft
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
6 changes: 4 additions & 2 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,8 @@ PHP_FUNCTION(socket_recvfrom)

if (arg6 == NULL) {
zend_string_efree(recv_buf);
WRONG_PARAM_COUNT;
zend_argument_value_error(6, "must be specified when argument #1 ($socket) is of type AF_INET or AF_INET6");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should stay ArgumentCountError, especially since it's an out parameter.

How about:

socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6, $x given.

RETURN_THROWS();
}

retval = recvfrom(php_sock->bsd_socket, ZSTR_VAL(recv_buf), arg3, arg4, (struct sockaddr *)&sin, (socklen_t *)&slen);
Expand All @@ -1607,7 +1608,8 @@ PHP_FUNCTION(socket_recvfrom)

if (arg6 == NULL) {
zend_string_efree(recv_buf);
WRONG_PARAM_COUNT;
zend_argument_value_error(6, "must be specified when argument #1 ($socket) is of type AF_INET or AF_INET6");
RETURN_THROWS();
}

retval = recvfrom(php_sock->bsd_socket, ZSTR_VAL(recv_buf), arg3, arg4, (struct sockaddr *)&sin6, (socklen_t *)&slen);
Expand Down
17 changes: 17 additions & 0 deletions ext/sockets/tests/socket_recvfrom_ipv4_missing_port_arg.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
socket_recvfrom() with IPv4 socket missing port argument
--EXTENSIONS--
sockets
--FILE--
<?php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

try {
socket_recvfrom($socket, $buffering, 20, 0, $address);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
ValueError: socket_recvfrom(): Argument #6 ($port) must be specified when argument #1 ($socket) is of type AF_INET or AF_INET6
17 changes: 17 additions & 0 deletions ext/sockets/tests/socket_recvfrom_ipv6_missing_port_arg.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
socket_recvfrom() with IPv6 socket missing port argument
--EXTENSIONS--
sockets
Copy link
Member

@devnexen devnexen Oct 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think you need ipv6_skipif.inc for this one.

--FILE--
<?php
$socket = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP);

try {
socket_recvfrom($socket, $buffering, 20, 0, $address);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
ValueError: socket_recvfrom(): Argument #6 ($port) must be specified when argument #1 ($socket) is of type AF_INET or AF_INET6