Skip to content

Commit 9993763

Browse files
committed
Check max UDS length of 104 bytes - server
1 parent 6727645 commit 9993763

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎src/UnixServer.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function __construct($path, LoopInterface $loop, array $context = array()
5353
throw new \InvalidArgumentException('Given URI "' . $path . '" is invalid');
5454
}
5555

56+
if (strlen($path) > 104) {
57+
throw new \InvalidArgumentException('Given URI "' . $path . '" exceeds maximum allowed length of 104 bytes');
58+
}
59+
5660
$this->master = @stream_socket_server(
5761
$path,
5862
$errno,

‎tests/UnixServerTest.php‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ private function createLoop()
1919

2020
/**
2121
* @covers React\Socket\UnixServer::__construct
22-
* @covers React\Socket\UnixServer::getAddress
2322
*/
2423
public function setUp()
2524
{
@@ -28,6 +27,14 @@ public function setUp()
2827
$this->server = new UnixServer($this->uds, $this->loop);
2928
}
3029

30+
/**
31+
* @covers React\Socket\UnixServer::getAddress
32+
*/
33+
public function testAddress()
34+
{
35+
$this->assertEquals($this->uds, $this->server->getAddress());
36+
}
37+
3138
/**
3239
* @covers React\Socket\UnixServer::handleConnection
3340
*/
@@ -260,6 +267,16 @@ public function testListenOnBusyPortThrows()
260267
$another = new UnixServer($this->uds, $this->loop);
261268
}
262269

270+
/**
271+
* @expectedException InvalidArgumentException
272+
*/
273+
public function testConnectWithOverlyLongAddress()
274+
{
275+
// string > 104 characters
276+
$path = "unix://" . sys_get_temp_dir() . DIRECTORY_SEPARATOR . str_repeat('_', 100) . '.sock';
277+
$another = new UnixServer($path, $this->loop);
278+
}
279+
263280
/**
264281
* @covers React\Socket\UnixServer::close
265282
*/

0 commit comments

Comments
 (0)