Skip to content

Commit 90707f3

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix socket_export_stream() with wrong protocol
2 parents 19886d3 + b5da98b commit 90707f3

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

ext/sockets/sockets.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,7 @@ PHP_FUNCTION(socket_export_stream)
22022202
php_socket *socket;
22032203
php_stream *stream = NULL;
22042204
php_netstream_data_t *stream_data;
2205-
char *protocol = NULL;
2205+
const char *protocol = NULL;
22062206
size_t protocollen = 0;
22072207

22082208
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zsocket, socket_ce) == FAILURE) {
@@ -2238,12 +2238,12 @@ PHP_FUNCTION(socket_export_stream)
22382238
if (protoid == IPPROTO_TCP)
22392239
#endif
22402240
{
2241-
protocol = "tcp";
2242-
protocollen = 3;
2241+
protocol = "tcp://";
2242+
protocollen = sizeof("tcp://") - 1;
22432243
}
22442244
} else if (protoid == SOCK_DGRAM) {
2245-
protocol = "udp";
2246-
protocollen = 3;
2245+
protocol = "udp://";
2246+
protocollen = sizeof("udp://") - 1;
22472247
}
22482248
#ifdef PF_UNIX
22492249
} else if (socket->type == PF_UNIX) {
@@ -2253,11 +2253,11 @@ PHP_FUNCTION(socket_export_stream)
22532253
getsockopt(socket->bsd_socket, SOL_SOCKET, SO_TYPE, (char *) &type, &typelen);
22542254

22552255
if (type == SOCK_STREAM) {
2256-
protocol = "unix";
2257-
protocollen = 4;
2256+
protocol = "unix://";
2257+
protocollen = sizeof("unix://") - 1;
22582258
} else if (type == SOCK_DGRAM) {
2259-
protocol = "udg";
2260-
protocollen = 3;
2259+
protocol = "udg://";
2260+
protocollen = sizeof("udg://") - 1;
22612261
}
22622262
#endif
22632263
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug - socket_export_stream() with wrong protocol
3+
--EXTENSIONS--
4+
sockets
5+
--FILE--
6+
<?php
7+
$sock = socket_create(AF_INET, SOCK_DGRAM, 0);
8+
$stream = socket_export_stream($sock);
9+
echo stream_get_meta_data($stream)['stream_type']. "\n";
10+
?>
11+
--EXPECT--
12+
udp_socket

0 commit comments

Comments
 (0)