diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-02-06 05:30:55 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-02-06 05:30:55 +0000 |
commit | ee6e1db1b624a75d9f1fedd42c95cbe673657c16 (patch) | |
tree | 8904f668410ca705cb114ed87874b25fdf6c3d88 /test | |
parent | 2618ffc57afe05308128e6ddf2b7fd2aae32b393 (diff) |
merge revision(s) 35474,35479,38939,38943,38963,38991,38994: [Backport #7786]
* ext/socket/raddrinfo.c (init_unix_addrinfo): support the longest
path in sockaddr_un.
(inspect_sockaddr): ditto.
(addrinfo_mdump): ditto.
(addrinfo_mload): ditto.
(rsock_unixpath_str): new function.
(rsock_unixpath): removed.
(rsock_unixaddr): use rsock_unixpath_str.
* ext/socket/socket.c (sock_s_pack_sockaddr_un): support the longest
path in sockaddr_un.
(sock_s_unpack_sockaddr_un): ditto.
(sock_s_gethostbyaddr): unused variable removed.
* ext/socket/unixsocket.c (rsock_init_unixsock): support the longest
path in sockaddr_un.
* ext/socket/rubysocket.h (rsock_unixpath_str): declared.
(rsock_unixpath): removed.
* test/socket/test_unix.rb: comment out test_nul because abstract unix
sockets may contain NULs.
* ext/socket/socket.c (sock_s_pack_sockaddr_un): support the longest
path in sockaddr_un, really.
reported by nagachika.
http://d.hatena.ne.jp/nagachika/20120426/ruby_trunk_changes_35474_35476
* 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.
* ext/socket/raddrinfo (rsock_unix_sockaddr_len): renamed from
rsock_unixpath_len, because it returns not the length of the path,
but the length of a socket address for the path.
* ext/socket/socket.c (sock_s_pack_sockaddr_un): calculate the
correct address length of an abstract socket.
* test/socket/test_unix.rb: related test.
* ext/socket/unixsocket.c (rsock_init_unixsock): use rb_inspect()
because rb_sys_fail_str() fails if its argument contains NUL.
* test/socket/test_unix.rb: related test.
* ext/socket/raddrinfo.c (rsock_unix_sockaddr_len): return
sizeof(sa_familiy_t) if path is empty. see "Autobind Feature" in
unix(7) for details.
* ext/socket/lib/socket.rb (unix_socket_abstract_name?): treat an
empty path as an abstract name.
* test/socket/test_unix.rb: related test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@39096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/socket/test_unix.rb | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb index b4c4592537..3559eb8a75 100644 --- a/test/socket/test_unix.rb +++ b/test/socket/test_unix.rb @@ -324,8 +324,11 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase assert_raise(ArgumentError) { UNIXServer.new("a" * 300) } end - def test_nul - assert_raise(ArgumentError) { Socket.sockaddr_un("a\0b") } + def test_abstract_namespace + return if /linux/ !~ RUBY_PLATFORM + addr = Socket.pack_sockaddr_un("\0foo") + assert_match(/\0foo\z/, addr) + assert_equal("\0foo", Socket.unpack_sockaddr_un(addr)) end def test_dgram_pair @@ -507,4 +510,69 @@ 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 + begin + assert_equal(name, c.remote_address.unix_path) + ensure + sock.close + end + } + } + assert(s0.closed?) + end + + def test_abstract_unix_socket_econnrefused + return if /linux/ !~ RUBY_PLATFORM + name = "\0ruby-test_unix" + assert_raise(Errno::ECONNREFUSED) do + UNIXSocket.open(name) {} + end + 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 + begin + assert_equal(name, c.remote_address.unix_path) + ensure + sock.close + end + } + } + assert(s0.closed?) + end + + def test_autobind + return if /linux/ !~ RUBY_PLATFORM + s0 = nil + Socket.unix_server_socket("") {|s| + name = s.local_address.unix_path + assert_match(/\A\0[0-9a-f]{5}\z/, name) + s0 = s + Socket.unix(name) {|c| + sock, = s.accept + begin + assert_equal(name, c.remote_address.unix_path) + ensure + sock.close + end + } + } + assert(s0.closed?) + end + end if defined?(UNIXSocket) && /cygwin/ !~ RUBY_PLATFORM |