* 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/trunk@28728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-07-23 00:02:51 +00:00
parent 85bf9bede4
commit 8044ac7b43
2 changed files with 14 additions and 6 deletions

View File

@ -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.
Fri Jul 23 09:00:05 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (XCFLAGS): reverted mistakenly removed option.

15
re.c
View File

@ -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);
}