Skip to content

Commit dcee59e

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix socket_export_stream() with wrong protocol
2 parents 14b8270 + d9b0bdb commit dcee59e

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
@@ -2268,7 +2268,7 @@ PHP_FUNCTION(socket_export_stream)
22682268
php_socket *socket;
22692269
php_stream *stream = NULL;
22702270
php_netstream_data_t *stream_data;
2271-
char *protocol = NULL;
2271+
const char *protocol = NULL;
22722272
size_t protocollen = 0;
22732273

22742274
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zsocket, socket_ce) == FAILURE) {
@@ -2304,12 +2304,12 @@ PHP_FUNCTION(socket_export_stream)
23042304
if (protoid == IPPROTO_TCP)
23052305
#endif
23062306
{
2307-
protocol = "tcp";
2308-
protocollen = 3;
2307+
protocol = "tcp://";
2308+
protocollen = sizeof("tcp://") - 1;
23092309
}
23102310
} else if (protoid == SOCK_DGRAM) {
2311-
protocol = "udp";
2312-
protocollen = 3;
2311+
protocol = "udp://";
2312+
protocollen = sizeof("udp://") - 1;
23132313
}
23142314
#ifdef PF_UNIX
23152315
} else if (socket->type == PF_UNIX) {
@@ -2319,11 +2319,11 @@ PHP_FUNCTION(socket_export_stream)
23192319
getsockopt(socket->bsd_socket, SOL_SOCKET, SO_TYPE, (char *) &type, &typelen);
23202320

23212321
if (type == SOCK_STREAM) {
2322-
protocol = "unix";
2323-
protocollen = 4;
2322+
protocol = "unix://";
2323+
protocollen = sizeof("unix://") - 1;
23242324
} else if (type == SOCK_DGRAM) {
2325-
protocol = "udg";
2326-
protocollen = 3;
2325+
protocol = "udg://";
2326+
protocollen = sizeof("udg://") - 1;
23272327
}
23282328
#endif
23292329
}
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)