Fix GH-12190: stream_context_create with address and port at 0.

Prior to the 8.1 rewrite, inet_aton was used for ipv4 addresses
therefore addresses like `0` passed.
For the bindto's case where both ip and port are set as such, we discard
the address binding.

Close GH-12195
This commit is contained in:
David Carlier 2023-09-12 22:45:24 +01:00
parent d93800ec0f
commit d65c80031a
3 changed files with 19 additions and 1 deletions

View file

@ -835,7 +835,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
case AF_INET:
((struct sockaddr_in *)sa)->sin_port = htons(port);
socklen = sizeof(struct sockaddr_in);
if (bindto && strchr(bindto, ':')) {
if (bindto && (strchr(bindto, ':') || !strcmp(bindto, "0"))) {
/* IPV4 sock can not bind to IPV6 address */
bindto = NULL;
}