Skip to content

Commit ccc8401

Browse files
committed
ext/sockets: socket_addrinfo_lookup() allows AF_UNSPEC for ai_family.
while still filtering out IPC like addresses and so on.
1 parent 824c389 commit ccc8401

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

ext/sockets/sockets.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,14 +2802,16 @@ PHP_FUNCTION(socket_addrinfo_lookup)
28022802
// Some platforms support also PF_LOCAL/AF_UNIX (e.g. FreeBSD) but the security concerns implied
28032803
// make it not worth handling it (e.g. unwarranted write permissions on the socket).
28042804
// Note existing socket_addrinfo* api already forbid such case.
2805+
if (val != AF_UNSPEC) {
28052806
#ifdef HAVE_IPV6
2806-
if (val != AF_INET && val != AF_INET6) {
2807-
zend_argument_value_error(3, "\"ai_family\" key must be AF_INET or AF_INET6");
2807+
if (val != AF_INET && val != AF_INET6) {
2808+
zend_argument_value_error(3, "\"ai_family\" key must be AF_INET or AF_INET6");
28082809
#else
2809-
if (val != AF_INET) {
2810-
zend_argument_value_error(3, "\"ai_family\" key must be AF_INET");
2810+
if (val != AF_INET) {
2811+
zend_argument_value_error(3, "\"ai_family\" key must be AF_INET");
28112812
#endif
2812-
RETURN_THROWS();
2813+
RETURN_THROWS();
2814+
}
28132815
}
28142816
hints.ai_family = (int)val;
28152817
} else {
@@ -2833,7 +2835,11 @@ PHP_FUNCTION(socket_addrinfo_lookup)
28332835
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
28342836

28352837
for (rp = result; rp != NULL; rp = rp->ai_next) {
2836-
if (rp->ai_family != AF_UNSPEC) {
2838+
if (rp->ai_family == AF_INET
2839+
#ifdef HAVE_IPV6
2840+
|| rp->ai_family != AF_INET6
2841+
#endif
2842+
) {
28372843
zval zaddr;
28382844

28392845
object_init_ex(&zaddr, address_info_ce);

ext/sockets/sockets.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
*/
2020
const AF_INET6 = UNKNOWN;
2121
#endif
22+
#ifdef AF_UNSPEC
23+
/**
24+
* @var int
25+
* @cvalue AF_UNSPEC
26+
*/
27+
const AF_UNSPEC = UNKNOWN;
28+
#endif
2229
#ifdef AF_DIVERT
2330
/**
2431
* @var int

ext/sockets/sockets_arginfo.h

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)