summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-24 10:39:35 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-24 10:39:35 +0000
commit3ee460750c501d91710da94ec483cb2318aa906a (patch)
treefcf768f397871f99cc3c080e5cfc2f26a412a086
parentb4f1675c777e497f2a5fb2c922c4710f58f84676 (diff)
merges r28728 from trunk into ruby_1_9_2.
-- * re.c (rb_reg_expr_str): fixed out-of-boundary access at invalid multibyte characters. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--re.c15
2 files changed, 14 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 14b7117b9e..6fa83202a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Jul 23 09:02:43 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * re.c (rb_reg_expr_str): fixed out-of-boundary access at invalid
+ multibyte characters.
+
Thu Jul 22 16:27:41 2010 NARUSE, Yui <naruse@ruby-lang.org>
* re.c (rb_reg_expr_str): fix broken Regexp#inspect when it
diff --git a/re.c b/re.c
index f0213235c9..8484c68ee2 100644
--- a/re.c
+++ b/re.c
@@ -370,18 +370,20 @@ rb_reg_expr_str(VALUE str, const char *s, long len,
rb_str_buf_cat(str, p, clen);
}
else if (c == -1) {
- int l;
+ clen = rb_enc_precise_mbclen(p, pend, enc);
+ if (!MBCLEN_CHARFOUND_P(clen)) {
+ c = (unsigned char)*p;
+ clen = 1;
+ goto hex;
+ }
if (resenc) {
unsigned int c = rb_enc_mbc_to_codepoint(p, pend, enc);
- l = rb_enc_codelen(c, enc);
rb_str_buf_cat_escaped_char(str, c, unicode_p);
}
else {
- l = mbclen(p, pend, enc);
- rb_str_buf_cat(str, p, l);
+ clen = MBCLEN_CHARFOUND_LEN(clen);
+ rb_str_buf_cat(str, p, clen);
}
- p += l;
- continue;
}
else if (rb_enc_isprint(c, enc)) {
rb_str_buf_cat(str, p, clen);
@@ -389,6 +391,7 @@ rb_reg_expr_str(VALUE str, const char *s, long len,
else if (!rb_enc_isspace(c, enc)) {
char b[8];
+ hex:
snprintf(b, sizeof(b), "\\x%02X", c);
rb_str_buf_cat(str, b, 4);
}