Commit f9e96d71 authored by Oliver Giles's avatar Oliver Giles

Support abstract unix socket addresses

Since kj::StringPtr supports embedded NULs, copy its entire data
buffer to the sockaddr_un structure instead of using strcpy.
On Linux, this allows the use of the abstract socket namespace.
parent 7728549b
...@@ -471,8 +471,11 @@ public: ...@@ -471,8 +471,11 @@ public:
KJ_REQUIRE(path.size() < sizeof(addr.unixDomain.sun_path), KJ_REQUIRE(path.size() < sizeof(addr.unixDomain.sun_path),
"Unix domain socket address is too long.", str); "Unix domain socket address is too long.", str);
result.addr.unixDomain.sun_family = AF_UNIX; result.addr.unixDomain.sun_family = AF_UNIX;
strcpy(result.addr.unixDomain.sun_path, path.cStr()); memcpy(result.addr.unixDomain.sun_path, path.cStr(), path.size() + 1);
result.addrlen = offsetof(struct sockaddr_un, sun_path) + path.size() + 1; result.addrlen = offsetof(struct sockaddr_un, sun_path) + path.size();
// Linux-specific: abstract namespace for unix sockets
// According to unix(7), addrlen of an abstract socket should not include the NULL terminator
if (path[0] != '\0') result.addrlen++;
auto array = kj::heapArrayBuilder<SocketAddress>(1); auto array = kj::heapArrayBuilder<SocketAddress>(1);
array.add(result); array.add(result);
return array.finish(); return array.finish();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment