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
25 changes: 15 additions & 10 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -2749,8 +2749,7 @@ PHP_FUNCTION(socket_export_stream)
/* {{{ Gets array with contents of getaddrinfo about the given hostname. */
PHP_FUNCTION(socket_addrinfo_lookup)
{
char *service = NULL;
size_t service_len = 0;
zend_string *service = NULL;
zend_string *hostname, *key;
zval *hint, *zhints = NULL;

Expand All @@ -2760,7 +2759,7 @@ PHP_FUNCTION(socket_addrinfo_lookup)
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_STR(hostname)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(service, service_len)
Z_PARAM_STR_OR_NULL(service)
Z_PARAM_ARRAY(zhints)
ZEND_PARSE_PARAMETERS_END();

Expand Down Expand Up @@ -2824,14 +2823,16 @@ PHP_FUNCTION(socket_addrinfo_lookup)
// Some platforms support also PF_LOCAL/AF_UNIX (e.g. FreeBSD) but the security concerns implied
// make it not worth handling it (e.g. unwarranted write permissions on the socket).
// Note existing socket_addrinfo* api already forbid such case.
Comment on lines 2823 to 2825
Copy link
Member

Choose a reason for hiding this comment

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

Does the comment need updating?

Copy link
Member Author

Choose a reason for hiding this comment

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

no it s still true, we still want to deal with only AF_INET*

if (val != AF_UNSPEC) {
#ifdef HAVE_IPV6
if (val != AF_INET && val != AF_INET6) {
zend_argument_value_error(3, "\"ai_family\" key must be AF_INET or AF_INET6");
if (val != AF_INET && val != AF_INET6) {
zend_argument_value_error(3, "\"ai_family\" key must be AF_INET or AF_INET6");
#else
if (val != AF_INET) {
zend_argument_value_error(3, "\"ai_family\" key must be AF_INET");
if (val != AF_INET) {
zend_argument_value_error(3, "\"ai_family\" key must be AF_INET");
#endif
RETURN_THROWS();
RETURN_THROWS();
}
}
hints.ai_family = (int)val;
} else {
Expand All @@ -2847,15 +2848,19 @@ PHP_FUNCTION(socket_addrinfo_lookup)
} ZEND_HASH_FOREACH_END();
}

if (getaddrinfo(ZSTR_VAL(hostname), service, &hints, &result) != 0) {
if (getaddrinfo(ZSTR_VAL(hostname), service ? ZSTR_VAL(service) : NULL, &hints, &result) != 0) {
RETURN_FALSE;
}

array_init(return_value);
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));

for (rp = result; rp != NULL; rp = rp->ai_next) {
if (rp->ai_family != AF_UNSPEC) {
if (rp->ai_family == AF_INET
#ifdef HAVE_IPV6
|| rp->ai_family == AF_INET6
#endif
) {
zval zaddr;

object_init_ex(&zaddr, address_info_ce);
Expand Down
7 changes: 7 additions & 0 deletions ext/sockets/sockets.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
*/
const AF_INET6 = UNKNOWN;
#endif
#ifdef AF_UNSPEC
/**
* @var int
* @cvalue AF_UNSPEC
*/
const AF_UNSPEC = UNKNOWN;
#endif
#ifdef AF_DIVERT
/**
* @var int
Expand Down
5 changes: 4 additions & 1 deletion ext/sockets/sockets_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading