summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-17 23:41:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-17 23:41:44 +0000
commite43c0bde5323c9dcd27ba284c1bdc7f11fa313ac (patch)
tree300e11fda0bc457cf727dc41f00be554431fbb6b
parent932591003708aac785a1e71ed6beb83e91554320 (diff)
* string.c (str_utf8_nth): fixed overrun. [ruby-core:26787]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--string.c1
-rw-r--r--test/ruby/test_m17n.rb5
3 files changed, 10 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index a7e0c62683..7cd75bf441 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Nov 18 08:41:42 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (str_utf8_nth): fixed overrun. [ruby-core:26787]
+
Wed Nov 18 07:51:01 2009 Tanaka Akira <akr@fsij.org>
* io.c (parse_mode_enc): fix invalid access.
diff --git a/string.c b/string.c
index 1cd5e7fbe4..f923b5f168 100644
--- a/string.c
+++ b/string.c
@@ -1483,6 +1483,7 @@ str_utf8_nth(const char *p, const char *e, long nth)
} while (s < t && (int)sizeof(VALUE) <= nth);
p = (char *)s;
}
+ if (p > e) return 0;
while (p < e) {
if (is_utf8_lead_byte(*p)) {
if (nth == 0) break;
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 1fa6d51288..e5c0acb034 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -867,6 +867,11 @@ class TestM17N < Test::Unit::TestCase
assert_equal(nil, u("\xc2\xa1\xc2\xa2\xc2\xa3")[u("\xa1\xc2")])
assert_raise(Encoding::CompatibilityError) { u("\xc2\xa1\xc2\xa2\xc2\xa3")[a("\xa1\xc2")] }
assert_nil(e("\xa1\xa2\xa3\xa4")[e("\xa2\xa3")])
+
+ bug2379 = '[ruby-core:26787]'
+ assert_equal("\u{439}", "\u{439}"[0, 30], bug2379)
+ assert_equal("\u{439}", "a\u{439}"[1, 30], bug2379)
+ assert_equal("\u{439}", "a\u{439}bcdefghijklmnop"[1, 1][0, 1], bug2379)
end
def test_aset