Skip to content
Open
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
13 changes: 11 additions & 2 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
+----------------------------------------------------------------------+
*/

#include "zend_exceptions.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
Expand Down Expand Up @@ -1580,7 +1581,11 @@ PHP_FUNCTION(socket_recvfrom)

if (arg6 == NULL) {
zend_string_efree(recv_buf);
WRONG_PARAM_COUNT;
zend_throw_exception(
Copy link
Member

Choose a reason for hiding this comment

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

not a bad idea. zend_argument_count_error could have been used too but you avoid 1 allocation at least.

zend_ce_argument_count_error,
"socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6",
0);
RETURN_THROWS();
}

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

if (arg6 == NULL) {
zend_string_efree(recv_buf);
WRONG_PARAM_COUNT;
zend_throw_exception(
zend_ce_argument_count_error,
"socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6",
0);
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--
ArgumentCountError: socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6
21 changes: 21 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,21 @@
--TEST--
socket_recvfrom() with IPv6 socket missing port argument
--EXTENSIONS--
sockets
--SKIPIF--
<?php
require 'ipv6_skipif.inc';
?>
--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--
ArgumentCountError: socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6