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

ruby-changes:48048

From: nobu <ko1@a...>
Date: Wed, 11 Oct 2017 15:16:08 +0900 (JST)
Subject: [ruby-changes:48048] nobu:r60162 (trunk): socket.c: null byte at Socket.getnameinfo

nobu	2017-10-11 15:16:04 +0900 (Wed, 11 Oct 2017)

  New Revision: 60162

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60162

  Log:
    socket.c: null byte at Socket.getnameinfo
    
    * ext/socket/socket.c (sock_s_getnameinfo): check null byte.
      patched by tommy (Masahiro Tomita) in [ruby-dev:50286].
      [Bug #13994]

  Modified files:
    trunk/ext/socket/socket.c
    trunk/test/socket/test_socket.rb
Index: test/socket/test_socket.rb
===================================================================
--- test/socket/test_socket.rb	(revision 60161)
+++ test/socket/test_socket.rb	(revision 60162)
@@ -105,6 +105,8 @@ class TestSocket < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/socket/test_socket.rb#L105
 
   def test_getnameinfo
     assert_raise(SocketError) { Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) }
+    assert_raise(ArgumentError) {Socket.getnameinfo(["AF_INET", "http\0", "example.net"])}
+    assert_raise(ArgumentError) {Socket.getnameinfo(["AF_INET", "http", "example.net\0"])}
   end
 
   def test_ip_address_list
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 60161)
+++ ext/socket/socket.c	(revision 60162)
@@ -1287,7 +1287,7 @@ sock_s_getnameinfo(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1287
 	    hptr = NULL;
 	}
 	else {
-	    strncpy(hbuf, StringValuePtr(host), sizeof(hbuf));
+	    strncpy(hbuf, StringValueCStr(host), sizeof(hbuf));
 	    hbuf[sizeof(hbuf) - 1] = '\0';
 	    hptr = hbuf;
 	}
@@ -1301,7 +1301,7 @@ sock_s_getnameinfo(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1301
 	    pptr = pbuf;
 	}
 	else {
-	    strncpy(pbuf, StringValuePtr(port), sizeof(pbuf));
+	    strncpy(pbuf, StringValueCStr(port), sizeof(pbuf));
 	    pbuf[sizeof(pbuf) - 1] = '\0';
 	    pptr = pbuf;
 	}

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

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