Skip to content

Commit e3f0d03

Browse files
committed
Fix GH-13603 ext/sockets: properly initialised address info data.
Led to random characters visible on socket id on macOs. Close GH-13606
1 parent 33967ae commit e3f0d03

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
. Fixed bug GH-13544 (Pre-PHP 8.2 compatibility for mt_srand with
1717
unknown modes). (timwolla)
1818

19+
- Sockets:
20+
. Fixed bug GH-13604 (socket_getsockname returns random characters in the
21+
end of the socket name). (David Carlier)
22+
1923
- SPL:
2024
. Fixed bug GH-13531 (Unable to resize SplfixedArray after being unserialized
2125
in PHP 8.2.15). (nielsdos)

ext/sockets/sockets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ PHP_FUNCTION(socket_read)
917917
PHP_FUNCTION(socket_getsockname)
918918
{
919919
zval *arg1, *addr, *port = NULL;
920-
php_sockaddr_storage sa_storage;
920+
php_sockaddr_storage sa_storage = {0};
921921
php_socket *php_sock;
922922
struct sockaddr *sa;
923923
struct sockaddr_in *sin;
@@ -994,7 +994,7 @@ PHP_FUNCTION(socket_getsockname)
994994
PHP_FUNCTION(socket_getpeername)
995995
{
996996
zval *arg1, *arg2, *arg3 = NULL;
997-
php_sockaddr_storage sa_storage;
997+
php_sockaddr_storage sa_storage = {0};
998998
php_socket *php_sock;
999999
struct sockaddr *sa;
10001000
struct sockaddr_in *sin;

ext/sockets/tests/gh13603.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
GH-13603 - socket_getsockname - invalid characters
3+
--EXTENSIONS--
4+
sockets
5+
--FILE--
6+
<?php
7+
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
8+
socket_bind($socket, 'sn.socp');
9+
socket_listen($socket);
10+
socket_getsockname($socket, $address);
11+
var_dump($address);
12+
socket_close($socket);
13+
unlink($address);
14+
--EXPECT--
15+
string(7) "sn.socp"

0 commit comments

Comments
 (0)