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

ruby-changes:43272

From: nobu <ko1@a...>
Date: Fri, 10 Jun 2016 14:48:48 +0900 (JST)
Subject: [ruby-changes:43272] nobu:r55345 (trunk): hash.c: ensure NUL-terminated for ENV

nobu	2016-06-10 14:48:38 +0900 (Fri, 10 Jun 2016)

  New Revision: 55345

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

  Log:
    hash.c: ensure NUL-terminated for ENV
    
    * hash.c (get_env_cstr): ensure NUL-terminated.
      [ruby-dev:49655] [Bug #12475]
    * string.c (rb_str_fill_terminator): return the pointer to the
      NUL-terminated content.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/internal.h
    trunk/string.c
    trunk/test/ruby/test_env.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55344)
+++ ChangeLog	(revision 55345)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jun 10 14:48:36 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (get_env_cstr): ensure NUL-terminated.
+	  [ruby-dev:49655] [Bug #12475]
+
+	* string.c (rb_str_fill_terminator): return the pointer to the
+	  NUL-terminated content.
+
 Thu Jun  9 21:42:00 2016  Kazuki Yamaguchi  <k@r...>
 
 	* ext/openssl/ossl_asn1.c (asn1integer_to_num): Use
Index: string.c
===================================================================
--- string.c	(revision 55344)
+++ string.c	(revision 55345)
@@ -2048,12 +2048,12 @@ rb_string_value_cstr(volatile VALUE *ptr https://github.com/ruby/ruby/blob/trunk/string.c#L2048
     return s;
 }
 
-void
+char *
 rb_str_fill_terminator(VALUE str, const int newminlen)
 {
     char *s = RSTRING_PTR(str);
     long len = RSTRING_LEN(str);
-    str_fill_term(str, s, len, newminlen);
+    return str_fill_term(str, s, len, newminlen);
 }
 
 VALUE
Index: hash.c
===================================================================
--- hash.c	(revision 55344)
+++ hash.c	(revision 55345)
@@ -2971,7 +2971,7 @@ get_env_cstr( https://github.com/ruby/ruby/blob/trunk/hash.c#L2971
     if (memchr(var, '\0', RSTRING_LEN(str))) {
 	rb_raise(rb_eArgError, "bad environment variable %s: contains null byte", name);
     }
-    return var;
+    return rb_str_fill_terminator(str, 1); /* ASCII compatible */
 }
 
 #ifdef _WIN32
Index: internal.h
===================================================================
--- internal.h	(revision 55344)
+++ internal.h	(revision 55345)
@@ -1350,7 +1350,7 @@ VALUE rb_str_quote_unprintable(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L1350
 VALUE rb_id_quote_unprintable(ID);
 #define QUOTE(str) rb_str_quote_unprintable(str)
 #define QUOTE_ID(id) rb_id_quote_unprintable(id)
-void rb_str_fill_terminator(VALUE str, const int termlen);
+char *rb_str_fill_terminator(VALUE str, const int termlen);
 VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg);
 #ifdef RUBY_ENCODING_H
 VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc);
Index: test/ruby/test_env.rb
===================================================================
--- test/ruby/test_env.rb	(revision 55344)
+++ test/ruby/test_env.rb	(revision 55345)
@@ -455,6 +455,20 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_env.rb#L455
     end
   end
 
+  def test_shared_substring
+    bug12475 = '[ruby-dev:49655] [Bug #12475]'
+    n = [*"0".."9"].join("")*3
+    e0 = ENV[n0 = "E#{n}"]
+    e1 = ENV[n1 = "E#{n}."]
+    ENV[n0] = nil
+    ENV[n1] = nil
+    ENV[n1.chop] = "T#{n}.".chop
+    ENV[n0], e0 = e0, ENV[n0]
+    ENV[n1], e1 = e1, ENV[n1]
+    assert_equal("T#{n}", e0, bug12475)
+    assert_nil(e1, bug12475)
+  end
+
   if RUBY_PLATFORM =~ /bccwin|mswin|mingw/
     def test_memory_leak_aset
       bug9977 = '[ruby-dev:48323] [Bug #9977]'

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

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