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

ruby-changes:43149

From: usa <ko1@a...>
Date: Tue, 31 May 2016 00:33:12 +0900 (JST)
Subject: [ruby-changes:43149] usa:r55222 (trunk): * ext/socket/raddrinfo.c (host_str, port_str): Use StringValueCStr

usa	2016-05-31 00:33:06 +0900 (Tue, 31 May 2016)

  New Revision: 55222

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

  Log:
    * ext/socket/raddrinfo.c (host_str, port_str): Use StringValueCStr
      instead of (Safe)StringValue, to detect NUL byte in the string.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/raddrinfo.c
    trunk/test/socket/test_addrinfo.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55221)
+++ ChangeLog	(revision 55222)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May 31 00:30:11 2016  NAKAMURA Usaku  <usa@r...>
+
+	* ext/socket/raddrinfo.c (host_str, port_str): Use StringValueCStr
+	  instead of (Safe)StringValue, to detect NUL byte in the string.
+
 Mon May 30 22:02:01 2016  Kazuki Yamaguchi  <k@r...>
 
 	* ext/openssl/ossl_asn1.c (time_to_time_t): Use NUM2TIMET() instead of
Index: ext/socket/raddrinfo.c
===================================================================
--- ext/socket/raddrinfo.c	(revision 55221)
+++ ext/socket/raddrinfo.c	(revision 55222)
@@ -429,6 +429,10 @@ str_is_number(const char *p) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L429
 #define str_equal(ptr, len, name) \
     ((ptr)[0] == name[0] && \
      rb_strlen_lit(name) == (len) && memcmp(ptr, name, len) == 0)
+#define SafeStringValueCStr(v) do {\
+    StringValueCStr(v);\
+    rb_check_safe_obj(v);\
+} while(0)
 
 static char*
 host_str(VALUE host, char *hbuf, size_t hbuflen, int *flags_ptr)
@@ -447,7 +451,7 @@ host_str(VALUE host, char *hbuf, size_t https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L451
         const char *name;
         size_t len;
 
-        SafeStringValue(host);
+        SafeStringValueCStr(host);
         RSTRING_GETMEM(host, name, len);
         if (!len || str_equal(name, len, "<any>")) {
             make_inetaddr(INADDR_ANY, hbuf, hbuflen);
@@ -486,7 +490,7 @@ port_str(VALUE port, char *pbuf, size_t https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L490
         const char *serv;
         size_t len;
 
-        SafeStringValue(port);
+        SafeStringValueCStr(port);
         RSTRING_GETMEM(port, serv, len);
         if (len >= pbuflen) {
             rb_raise(rb_eArgError, "service name too long (%"PRIdSIZE")",
Index: test/socket/test_addrinfo.rb
===================================================================
--- test/socket/test_addrinfo.rb	(revision 55221)
+++ test/socket/test_addrinfo.rb	(revision 55222)
@@ -42,6 +42,9 @@ class TestSocketAddrinfo < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/socket/test_addrinfo.rb#L42
       Addrinfo.ip(addr)
     end
     assert_equal([0, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
+    assert_raise(ArgumentError) do
+      Addrinfo.ip("127.0.0.1\000x")
+    end
   end
 
   def test_addrinfo_tcp
@@ -56,6 +59,9 @@ class TestSocketAddrinfo < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/socket/test_addrinfo.rb#L59
       Addrinfo.tcp("127.0.0.1", "0000000000000000000000080x".chop)
     end
     assert_equal([80, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
+    assert_raise(ArgumentError) do
+      Addrinfo.ip("127.0.0.1", "80\000x")
+    end
   end
 
   def test_addrinfo_udp

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

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