Merge branch 'PHP-8.3'

* PHP-8.3:
  Fix socket_export_stream() with wrong protocol
This commit is contained in:
twosee 2023-09-29 18:59:17 +08:00
commit dcee59eb33
No known key found for this signature in database
GPG key ID: 0450D9046197760D
2 changed files with 21 additions and 9 deletions

View file

@ -2268,7 +2268,7 @@ PHP_FUNCTION(socket_export_stream)
php_socket *socket;
php_stream *stream = NULL;
php_netstream_data_t *stream_data;
char *protocol = NULL;
const char *protocol = NULL;
size_t protocollen = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zsocket, socket_ce) == FAILURE) {
@ -2304,12 +2304,12 @@ PHP_FUNCTION(socket_export_stream)
if (protoid == IPPROTO_TCP)
#endif
{
protocol = "tcp";
protocollen = 3;
protocol = "tcp://";
protocollen = sizeof("tcp://") - 1;
}
} else if (protoid == SOCK_DGRAM) {
protocol = "udp";
protocollen = 3;
protocol = "udp://";
protocollen = sizeof("udp://") - 1;
}
#ifdef PF_UNIX
} else if (socket->type == PF_UNIX) {
@ -2319,11 +2319,11 @@ PHP_FUNCTION(socket_export_stream)
getsockopt(socket->bsd_socket, SOL_SOCKET, SO_TYPE, (char *) &type, &typelen);
if (type == SOCK_STREAM) {
protocol = "unix";
protocollen = 4;
protocol = "unix://";
protocollen = sizeof("unix://") - 1;
} else if (type == SOCK_DGRAM) {
protocol = "udg";
protocollen = 3;
protocol = "udg://";
protocollen = sizeof("udg://") - 1;
}
#endif
}

View file

@ -0,0 +1,12 @@
--TEST--
Bug - socket_export_stream() with wrong protocol
--EXTENSIONS--
sockets
--FILE--
<?php
$sock = socket_create(AF_INET, SOCK_DGRAM, 0);
$stream = socket_export_stream($sock);
echo stream_get_meta_data($stream)['stream_type']. "\n";
?>
--EXPECT--
udp_socket