Skip to content

Commit 8dcfec9

Browse files
committed
Bugfix #74556 stream_socket_get_name() returns empty string
The original bug report had it returning '\0', but with a fix to abstract name handling (6d2d0bb) it now actually returns ''. Neither of these are good, as per unix(7) an empty socket name indicates an unbound name and "should not be inspected".
1 parent 6d2d0bb commit 8dcfec9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- Core:
66
. Fixed bug #74658 (Undefined constants in array properties result in broken
77
properties). (Laruence)
8+
. Fixed misparsing of abstract unix domain socket names. (Sara)
89

910
- Opcache:
1011
. Fixed bug #74663 (Segfault with opcache.memory_protect and
@@ -17,6 +18,9 @@ PHP NEWS
1718
- FTP:
1819
. Fixed bug #74598 (ftp:// wrapper ignores context arg). (Sara)
1920

21+
- Streams:
22+
. Fixed bug #74556 (stream_socket_get_name() returns '\0'). (Sara)
23+
2024
8 Jun 2017 PHP 7.0.20
2125

2226
- Core:

ext/standard/streamsfuncs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ PHP_FUNCTION(stream_socket_get_name)
314314
RETURN_FALSE;
315315
}
316316

317+
if (!ZSTR_LEN(name)) {
318+
zend_string_release(name);
319+
RETURN_FALSE;
320+
}
321+
317322
RETVAL_STR(name);
318323
}
319324
/* }}} */
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #74556 stream_socket_get_name() on unix socket returns "\0"
3+
--SKIPIF--
4+
<?php
5+
if (!strncasecmp(PHP_OS, 'WIN', 3)) echo "skip Unix Only";
6+
--FILE--
7+
<?php
8+
9+
$sock = __DIR__ . '/bug74556.sock';
10+
$s = stream_socket_server("unix://$sock");
11+
$c = stream_socket_client("unix://$sock");
12+
13+
var_dump(
14+
stream_socket_get_name($s, true),
15+
stream_socket_get_name($c, false)
16+
);
17+
--CLEAN--
18+
<?php
19+
unlink(__DIR__ . '/bug74556.sock');
20+
--EXPECT--
21+
bool(false)
22+
bool(false)

0 commit comments

Comments
 (0)