mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
ext/sockets: socket_addrinfo_lookup and other few internal changes
- socket_addrinfo_lookup throws when hints is an indexed array. - socket_get_option hardcoding size outputs to user when data size known. close GH-17363
This commit is contained in:
2
NEWS
2
NEWS
@@ -92,6 +92,8 @@ PHP NEWS
|
||||
(David Carlier)
|
||||
. socket_addrinfo_lookup throws an exception if any of the hints value
|
||||
overflows. (David Carlier)
|
||||
. socket_addrinfo_lookup throws an exception if one or more hints entries
|
||||
has an index as numeric. (David Carlier)
|
||||
|
||||
- Standard:
|
||||
. Fixed crypt() tests on musl when using --with-external-libcrypt
|
||||
|
||||
@@ -126,7 +126,8 @@ PHP 8.5 UPGRADE NOTES
|
||||
|
||||
- Sockets:
|
||||
. socket_create_listen, socket_bind and socket_sendto throw a
|
||||
ValueError if the port is lower than 0 or greater than 65535.
|
||||
ValueError if the port is lower than 0 or greater than 65535,
|
||||
also if any of the hints array entry is indexes numerically.
|
||||
. socket_addrinfo_lookup throw a TypeError if any of the hints
|
||||
values cannot be cast to a int and can throw a ValueError if
|
||||
any of these values overflow.
|
||||
|
||||
@@ -1741,7 +1741,7 @@ PHP_FUNCTION(socket_get_option)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
array_init_size(return_value, 2);
|
||||
|
||||
add_assoc_string(return_value, "function_set_name", tsf.function_set_name);
|
||||
add_assoc_long(return_value, "pcbcnt", tsf.pcbcnt);
|
||||
@@ -1764,7 +1764,7 @@ PHP_FUNCTION(socket_get_option)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
array_init_size(return_value, 2);
|
||||
add_assoc_long(return_value, "l_onoff", linger_val.l_onoff);
|
||||
add_assoc_long(return_value, "l_linger", linger_val.l_linger);
|
||||
return;
|
||||
@@ -1786,7 +1786,7 @@ PHP_FUNCTION(socket_get_option)
|
||||
tv.tv_usec = timeout ? (long)((timeout % 1000) * 1000) : 0;
|
||||
#endif
|
||||
|
||||
array_init(return_value);
|
||||
array_init_size(return_value, 2);
|
||||
|
||||
add_assoc_long(return_value, "sec", tv.tv_sec);
|
||||
add_assoc_long(return_value, "usec", tv.tv_usec);
|
||||
@@ -1808,7 +1808,7 @@ PHP_FUNCTION(socket_get_option)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
array_init_size(return_value, 9);
|
||||
|
||||
add_assoc_long(return_value, "rmem_alloc", minfo[SK_MEMINFO_RMEM_ALLOC]);
|
||||
add_assoc_long(return_value, "rcvbuf", minfo[SK_MEMINFO_RCVBUF]);
|
||||
@@ -1833,7 +1833,7 @@ PHP_FUNCTION(socket_get_option)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
array_init_size(return_value, 1);
|
||||
|
||||
add_assoc_string(return_value, "af_name", af.af_name);
|
||||
return;
|
||||
@@ -1857,9 +1857,11 @@ PHP_FUNCTION(socket_get_option)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
size_t arrlen = optlen / sizeof(struct fil_info);
|
||||
|
||||
for (i = 0; i < optlen / sizeof(struct fil_info); i++) {
|
||||
array_init_size(return_value, arrlen);
|
||||
|
||||
for (i = 0; i < arrlen; i++) {
|
||||
add_index_string(return_value, i, fi[i].fi_name);
|
||||
}
|
||||
|
||||
@@ -2589,7 +2591,13 @@ PHP_FUNCTION(socket_addrinfo_lookup)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (zhints && !HT_IS_PACKED(Z_ARRVAL_P(zhints))) {
|
||||
if (zhints) {
|
||||
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\"");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zhints), key, hint) {
|
||||
if (key) {
|
||||
bool failed = false;
|
||||
@@ -2639,9 +2647,13 @@ PHP_FUNCTION(socket_addrinfo_lookup)
|
||||
hints.ai_family = (int)val;
|
||||
} else {
|
||||
zend_argument_value_error(3, "must only contain array keys \"ai_flags\", \"ai_socktype\", "
|
||||
"\"ai_protocol\", or \"ai_family\"");
|
||||
"\"ai_protocol\", or \"ai_family\"");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
zend_argument_value_error(3, "must only contain array keys \"ai_flags\", \"ai_socktype\", "
|
||||
"\"ai_protocol\", or \"ai_family\"");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
}
|
||||
|
||||
@@ -84,6 +84,26 @@ try {
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
try {
|
||||
socket_addrinfo_lookup('127.0.0.1', 2000, [
|
||||
AF_INET,
|
||||
SOCK_DGRAM,
|
||||
0,
|
||||
0,
|
||||
]);
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
try {
|
||||
socket_addrinfo_lookup('127.0.0.1', 2000, array(
|
||||
'ai_family' => AF_INET,
|
||||
'ai_socktype' => SOCK_DGRAM,
|
||||
0,
|
||||
0,
|
||||
));
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
socket_addrinfo_lookup(): Argument #3 ($hints) "ai_family" key must be of type int, stdClass given
|
||||
@@ -94,3 +114,5 @@ socket_addrinfo_lookup(): Argument #3 ($hints) "ai_family" key must be between 0
|
||||
socket_addrinfo_lookup(): Argument #3 ($hints) "ai_socktype" key must be between 0 and %d
|
||||
socket_addrinfo_lookup(): Argument #3 ($hints) "ai_flags" key must be between 0 and %d
|
||||
socket_addrinfo_lookup(): Argument #3 ($hints) "ai_protocol" key must be between 0 and %d
|
||||
socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family"
|
||||
socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family"
|
||||
|
||||
Reference in New Issue
Block a user