diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-25 08:15:26 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-25 08:15:26 +0000 |
commit | ad55d141ebd0922be310b66c8e4c0e81e94521d1 (patch) | |
tree | f13d4d87daf11313efb560d8e85ddc1a4a2ceb6a /test/socket | |
parent | 76ade818ae8bc3bc72979e5fa880add04b165636 (diff) | |
download | ruby-ad55d141ebd0922be310b66c8e4c0e81e94521d1.tar.gz |
* ext/socket/raddrinfo.c (rsock_unixpath_len, init_unix_addrinfo),
ext/socket/unixsocket.c (unixsock_connect_internal,
rsock_init_unixsock): calculate the correct address length of
an abstract socket. Without this fix, sizeof(struct sockaddr_un)
is specified as the length of an abstract socket for bind(2) or
connect(2), so the address of the socket is filled with extra NUL
characters. See unix(7) for details.
* ext/socket/lib/socket.rb (unix_server_socket): don't access the
file system if the platform is Linux and path starts with NUL,
which means that the socket is an abstract socket.
* test/socket/test_unix.rb: related test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/socket')
-rw-r--r-- | test/socket/test_unix.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb index 1c5395e380..a44ef2de38 100644 --- a/test/socket/test_unix.rb +++ b/test/socket/test_unix.rb @@ -531,4 +531,34 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase } end + def test_abstract_unix_server + return if /linux/ !~ RUBY_PLATFORM + name = "\0ruby-test_unix" + s0 = nil + UNIXServer.open(name) {|s| + assert_equal(name, s.local_address.unix_path) + s0 = s + UNIXSocket.open(name) {|c| + sock = s.accept + assert_equal(name, c.remote_address.unix_path) + } + } + assert(s0.closed?) + end + + def test_abstract_unix_server_socket + return if /linux/ !~ RUBY_PLATFORM + name = "\0ruby-test_unix" + s0 = nil + Socket.unix_server_socket(name) {|s| + assert_equal(name, s.local_address.unix_path) + s0 = s + Socket.unix(name) {|c| + sock, = s.accept + assert_equal(name, c.remote_address.unix_path) + } + } + assert(s0.closed?) + end + end if defined?(UNIXSocket) && /cygwin/ !~ RUBY_PLATFORM |