[前][次][番号順一覧][スレッド一覧]

ruby-changes:26912

From: shugo <ko1@a...>
Date: Tue, 29 Jan 2013 09:32:50 +0900 (JST)
Subject: [ruby-changes:26912] shugo:r38963 (trunk): * ext/socket/socket.c (sock_s_pack_sockaddr_un): calculate the

shugo	2013-01-29 09:32:05 +0900 (Tue, 29 Jan 2013)

  New Revision: 38963

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38963

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/socket.c
    trunk/test/socket/test_unix.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38962)
+++ ChangeLog	(revision 38963)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jan 29 09:26:20 2013  Shugo Maeda  <shugo@r...>
+
+	* 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.
+
 Mon Jan 28 18:02:16 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_backtrace.c (rb_debug_inspector_frame_{class,binding,iseq}_get):
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 38962)
+++ ext/socket/socket.c	(revision 38963)
@@ -1430,7 +1430,7 @@ sock_s_pack_sockaddr_un(VALUE self, VALU https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1430
             (size_t)RSTRING_LEN(path), sizeof(sockaddr.sun_path));
     }
     memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
-    addr = rb_str_new((char*)&sockaddr, sizeof(sockaddr));
+    addr = rb_str_new((char*)&sockaddr, rsock_unix_sockaddr_len(path));
     OBJ_INFECT(addr, path);
 
     return addr;
Index: test/socket/test_unix.rb
===================================================================
--- test/socket/test_unix.rb	(revision 38962)
+++ test/socket/test_unix.rb	(revision 38963)
@@ -339,10 +339,12 @@ class TestSocket_UNIXSocket < Test::Unit https://github.com/ruby/ruby/blob/trunk/test/socket/test_unix.rb#L339
     assert_raise(ArgumentError) { UNIXServer.new("a" * 300) }
   end
 
-  #def test_nul
-  #  # path may contain NULs for abstract unix sockets.  [ruby-core:10288]
-  #  assert_raise(ArgumentError) { Socket.sockaddr_un("a\0b") }
-  #end
+  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
     s1, s2 = UNIXSocket.pair(Socket::SOCK_DGRAM)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]