Skip to content

Commit fd1c366

Browse files
committed
ext/sockets: socket_recvfrom() improve error message when port argument is missing
1 parent 4e562f4 commit fd1c366

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

ext/sockets/sockets.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
+----------------------------------------------------------------------+
1919
*/
2020

21+
#include "zend_exceptions.h"
2122
#ifdef HAVE_CONFIG_H
2223
#include <config.h>
2324
#endif
@@ -1580,7 +1581,11 @@ PHP_FUNCTION(socket_recvfrom)
15801581

15811582
if (arg6 == NULL) {
15821583
zend_string_efree(recv_buf);
1583-
WRONG_PARAM_COUNT;
1584+
zend_throw_exception(
1585+
zend_ce_argument_count_error,
1586+
"socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6",
1587+
0);
1588+
RETURN_THROWS();
15841589
}
15851590

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

16081613
if (arg6 == NULL) {
16091614
zend_string_efree(recv_buf);
1610-
WRONG_PARAM_COUNT;
1615+
zend_throw_exception(
1616+
zend_ce_argument_count_error,
1617+
"socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6",
1618+
0);
1619+
RETURN_THROWS();
16111620
}
16121621

16131622
retval = recvfrom(php_sock->bsd_socket, ZSTR_VAL(recv_buf), arg3, arg4, (struct sockaddr *)&sin6, (socklen_t *)&slen);

ext/sockets/tests/socket_recvfrom_ipv4_missing_port_arg.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ try {
1414

1515
?>
1616
--EXPECT--
17-
ArgumentCountError: Wrong parameter count for socket_recvfrom()
17+
ArgumentCountError: socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6

ext/sockets/tests/socket_recvfrom_ipv6_missing_port_arg.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ try {
1818

1919
?>
2020
--EXPECT--
21-
ArgumentCountError: Wrong parameter count for socket_recvfrom()
21+
ArgumentCountError: socket_recvfrom() expects exactly 6 arguments when argument #1 ($socket) is of type AF_INET or AF_INET6

0 commit comments

Comments
 (0)