From 5703943081fc24d555e572edf507a05702974d98 Mon Sep 17 00:00:00 2001 From: viest Date: Sat, 3 Aug 2019 23:05:56 +0800 Subject: [PATCH] Deprecate AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES These flags have been deprecated in glibc 2.28, so we also deprecate them in PHP. As we can't deprecate constants, we can only check for their use in socket_addrinfo_lookup(). --- UPGRADING | 5 +++++ ext/sockets/sockets.c | 9 ++++++++- ext/sockets/tests/ai_idn_deprecation.phpt | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 ext/sockets/tests/ai_idn_deprecation.phpt diff --git a/UPGRADING b/UPGRADING index 3e4879c6ef..0cef7fc43d 100644 --- a/UPGRADING +++ b/UPGRADING @@ -404,6 +404,11 @@ PHP 7.4 UPGRADE NOTES // $str = ReflectionClass::export(Foo::class, true) is: $str = (string) new ReflectionClass(Foo::class); +- Socket: + . The AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES flags for + socket_addrinfo_lookup() are deprecated, due to an upstream deprecation in + glibc. + - Standard: . Passing invalid characters to ''base_convert()'', ''bindec()'', ''octdec()'' and ''hexdec()'' will now generate a deprecation notice. The result will diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 18c124740a..21538e92e1 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -2573,7 +2573,14 @@ PHP_FUNCTION(socket_addrinfo_lookup) ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zhints), key, hint) { if (key) { if (zend_string_equals_literal(key, "ai_flags")) { - hints.ai_flags = zval_get_long(hint); + zend_long flags = zval_get_long(hint); +#if HAVE_AI_IDN + if (flags & (AI_IDN_ALLOW_UNASSIGNED | AI_IDN_USE_STD3_ASCII_RULES)) { + php_error_docref(NULL, E_DEPRECATED, + "AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES are deprecated"); + } +#endif + hints.ai_flags = flags; } else if (zend_string_equals_literal(key, "ai_socktype")) { hints.ai_socktype = zval_get_long(hint); } else if (zend_string_equals_literal(key, "ai_protocol")) { diff --git a/ext/sockets/tests/ai_idn_deprecation.phpt b/ext/sockets/tests/ai_idn_deprecation.phpt new file mode 100644 index 0000000000..02a6965d26 --- /dev/null +++ b/ext/sockets/tests/ai_idn_deprecation.phpt @@ -0,0 +1,20 @@ +--TEST-- +AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES are deprecated +--SKIPIF-- + +--FILE-- + AF_INET, + 'ai_socktype' => SOCK_DGRAM, + 'ai_flags' => AI_IDN_ALLOW_UNASSIGNED, +)); +var_dump(socket_addrinfo_connect($addrinfo[0])); +echo "Done"; +--EXPECTF-- +Deprecated: socket_addrinfo_lookup(): AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES are deprecated in %s on line %d +resource(%d) of type (Socket) +Done -- 2.50.0