Skip to content
Closed
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
32 changes: 22 additions & 10 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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]);
Expand All @@ -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;
Expand All @@ -1857,9 +1857,11 @@ PHP_FUNCTION(socket_get_option)
RETURN_FALSE;
}

array_init(return_value);
size_t arrlen = optlen / sizeof(struct fil_info);

array_init_size(return_value, arrlen);

for (i = 0; i < optlen / sizeof(struct fil_info); i++) {
for (i = 0; i < arrlen; i++) {
add_index_string(return_value, i, fi[i].fi_name);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
22 changes: 22 additions & 0 deletions ext/sockets/tests/socket_getaddrinfo_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Loading