1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-06-10 05:48:38 +00:00
parent f9843bc4dc
commit 2667d1b38f
5 changed files with 26 additions and 4 deletions

View file

@ -1,3 +1,11 @@
Fri Jun 10 14:48:36 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@rhe.jp>
* ext/openssl/ossl_asn1.c (asn1integer_to_num): Use

2
hash.c
View file

@ -2971,7 +2971,7 @@ get_env_cstr(
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

View file

@ -1350,7 +1350,7 @@ VALUE rb_str_quote_unprintable(VALUE);
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);

View file

@ -2048,12 +2048,12 @@ rb_string_value_cstr(volatile VALUE *ptr)
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

View file

@ -455,6 +455,20 @@ class TestEnv < Test::Unit::TestCase
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]'