[php-src] master: ext/sockets: Accept an empty packed hints array in socket_addrinfo_lookup()

From: Date: Thu, 12 Nov 2026 18:31:57 +0000
Subject: [php-src] master: ext/sockets: Accept an empty packed hints array in socket_addrinfo_lookup()
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143647@lists.php.net to get a copy of this message
Author: lacatoire (lacatoire) Committer: David Carlier (devnexen) Date: 2026-11-12T18:26:59Z Commit: https://github.com/php/php-src/commit/ebf5029b421aeb0c944d4316eb869b9a17d4e17f Raw diff: https://github.com/php/php-src/commit/ebf5029b421aeb0c944d4316eb869b9a17d4e17f.diff ext/sockets: Accept an empty packed hints array in socket_addrinfo_lookup() socket_addrinfo_lookup() throws a ValueError for an empty packed $hints (left by unset()), while [] is accepted. Skip empty hints. Close GH-24747 Changed paths: A ext/sockets/tests/socket_addrinfo_lookup_empty_packed_hints.phpt M NEWS M ext/sockets/sockets.c Diff: diff --git a/NEWS b/NEWS index 2b7c0a0e6ab8..6fb099bd856c 100644 --- a/NEWS +++ b/NEWS @@ -86,6 +86,10 @@ PHP NEWS . Fix trampoline leak when object construction fails for lazy object. (ndossche) +- Sockets: + . Fixed socket_addrinfo_lookup() rejecting an empty packed hints array. + (lacatoire) + - Streams: . Fixed in-place URL decoding of interned strings in the HTTP and FTP wrappers. (Alejandro Pacheco) diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 6aa14c06bdd0..4dec5fb33430 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -2768,7 +2768,7 @@ PHP_FUNCTION(socket_addrinfo_lookup) # endif #endif - if (zhints) { + if (zhints && zend_hash_num_elements(Z_ARRVAL_P(zhints)) > 0) { if (UNEXPECTED(HT_IS_PACKED(Z_ARRVAL_P(zhints)))) { zend_argument_value_error(3, "must only contain array keys \"ai_flags\", \"ai_socktype\", " "\"ai_protocol\", or \"ai_family\""); diff --git a/ext/sockets/tests/socket_addrinfo_lookup_empty_packed_hints.phpt b/ext/sockets/tests/socket_addrinfo_lookup_empty_packed_hints.phpt new file mode 100644 index 000000000000..6905a1bad17d --- /dev/null +++ b/ext/sockets/tests/socket_addrinfo_lookup_empty_packed_hints.phpt @@ -0,0 +1,21 @@ +--TEST-- +socket_addrinfo_lookup(): an empty packed hints array is accepted like [] +--EXTENSIONS-- +sockets +--FILE-- +<?php +$hints = [1]; +unset($hints[0]); +var_dump(count($hints), $hints === []); +var_dump(count(socket_addrinfo_lookup('127.0.0.1', '80', $hints)) === count(socket_addrinfo_lookup('127.0.0.1', '80', []))); +try { + socket_addrinfo_lookup('127.0.0.1', '80', [1]); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} +?> +--EXPECT-- +int(0) +bool(true) +bool(true) +ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family"

« previous php.cvs (#143647) next »