Skip to content

Fix Issue 20544 - socket.remoteAddress throws out of memory error with unix domain socket peer #7383

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

Merged
merged 1 commit into from
Jan 30, 2020
Merged
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: 8 additions & 0 deletions std/socket.d
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,8 @@ static if (is(sockaddr_un))
@property string path() @trusted const pure
{
auto len = _nameLen - sockaddr_un.init.sun_path.offsetof;
if (len == 0)
return null; // An empty path may be returned from getpeername
// For pathname socket address we need to strip off the terminating '\0'
if (sun.sun_path.ptr[0])
--len;
Expand Down Expand Up @@ -2073,6 +2075,12 @@ static if (is(sockaddr_un))
auto buf = new ubyte[data.length];
pair[1].receive(buf);
assert(buf == data);

// getpeername is free to return an empty name for a unix
// domain socket pair or unbound socket. Let's confirm it
// returns successfully and doesn't throw anything.
// See https://issues.dlang.org/show_bug.cgi?id=20544
assertNotThrown(pair[1].remoteAddress().toString());
}
}
}
Expand Down