Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent exception if underlying socket is a unix socket #234

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/RequestHeaderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ private function parseRequest($headers)

if ($this->remoteSocketUri !== null) {
$remoteAddress = parse_url($this->remoteSocketUri);
$serverParams['REMOTE_ADDR'] = $remoteAddress['host'];
$serverParams['REMOTE_PORT'] = $remoteAddress['port'];

// port won't be set for unix domain sockets
if (isset($remoteAddress['port'])) {
$serverParams['REMOTE_ADDR'] = $remoteAddress['host'];
$serverParams['REMOTE_PORT'] = $remoteAddress['port'];
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the REMOTE_ADDR should still be set, no? I guess the port could just be set to 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of OSX I get ________ as REMOTE_ADDR so I've removed both.

}

if ($this->localSocketUri !== null) {
Expand Down
12 changes: 12 additions & 0 deletions tests/RequestHeaderParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,18 @@ public function testQueryParmetersWillBeSet()
$this->assertEquals('this', $queryParams['test']);
}

public function testUnixRemoteSocketWithoutPort()
{
// reactphp/socket Connect->parseAddress returns "tcp://NUL" for UDS
$parser = new RequestHeaderParser(null, 'tcp://' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these empty string concatenations?

Copy link
Contributor Author

@andig andig Oct 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://bugs.php.net/bug.php?id=74556. Thats what PHP returns for stream address of UDS on OSX. I would appreciated upvotes on the bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andig Thanks for the update!

Have you seen reactphp/socket#100? IMO this should be handled by the Socket component, which is also where this address comes from (afaict). This way, we would likely expect a null address here. Does this make sense to you?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want upvotes on an already fixed bug? But it's not what I asked. You write "\0" . '' . "\0" there instead of simply "\0\0", why that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You write "\0" . '' . "\0" there instead of simply "\0\0", why that?

That was copy/paste from var_export, will fix.


$parser->on('error', $this->expectCallableNever());

$data = $this->createGetRequest();
$parser->feed($data);

}

private function createGetRequest()
{
$data = "GET / HTTP/1.1\r\n";
Expand Down