mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
unicode.c: boundary check
* enc/unicode.c (CodePointListValidP): add pathological boundary check, for gcc 4.9. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
12ec73ad92
commit
d48f923648
1 changed files with 14 additions and 6 deletions
|
@ -431,6 +431,8 @@ onigenc_unicode_apply_all_case_fold(OnigCaseFoldType flag,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CodePointListValidP(x) (OnigCodePointCount((x)->n) < numberof((x)->code))
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
||||||
OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end,
|
OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end,
|
||||||
|
@ -483,7 +485,8 @@ onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
code = to->code[0];
|
code = to->code[0];
|
||||||
if ((to = onigenc_unicode_unfold1_lookup(code)) != 0) {
|
if ((to = onigenc_unicode_unfold1_lookup(code)) != 0 &&
|
||||||
|
CodePointListValidP(to)) {
|
||||||
for (i = 0; i < OnigCodePointCount(to->n); i++) {
|
for (i = 0; i < OnigCodePointCount(to->n); i++) {
|
||||||
if (to->code[i] != orig_code) {
|
if (to->code[i] != orig_code) {
|
||||||
items[n].byte_len = len;
|
items[n].byte_len = len;
|
||||||
|
@ -521,7 +524,8 @@ onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((z2 = onigenc_unicode_unfold2_lookup(to->code)) != 0) {
|
if ((z2 = onigenc_unicode_unfold2_lookup(to->code)) != 0 &&
|
||||||
|
CodePointListValidP(z2)) {
|
||||||
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
||||||
if (z2->code[i] == code) continue;
|
if (z2->code[i] == code) continue;
|
||||||
|
|
||||||
|
@ -546,7 +550,8 @@ onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((z2 = onigenc_unicode_unfold3_lookup(to->code)) != 0) {
|
if ((z2 = onigenc_unicode_unfold3_lookup(to->code)) != 0 &&
|
||||||
|
CodePointListValidP(z2)) {
|
||||||
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
||||||
if (z2->code[i] == code) continue;
|
if (z2->code[i] == code) continue;
|
||||||
|
|
||||||
|
@ -563,7 +568,8 @@ onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((to = onigenc_unicode_unfold1_lookup(code)) != 0) {
|
if ((to = onigenc_unicode_unfold1_lookup(code)) != 0 &&
|
||||||
|
CodePointListValidP(to)) {
|
||||||
for (i = 0; i < OnigCodePointCount(to->n); i++) {
|
for (i = 0; i < OnigCodePointCount(to->n); i++) {
|
||||||
items[n].byte_len = len;
|
items[n].byte_len = len;
|
||||||
items[n].code_len = 1;
|
items[n].code_len = 1;
|
||||||
|
@ -590,7 +596,8 @@ onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
||||||
|
|
||||||
clen = enclen(enc, p, end);
|
clen = enclen(enc, p, end);
|
||||||
len += clen;
|
len += clen;
|
||||||
if ((z2 = onigenc_unicode_unfold2_lookup(codes)) != 0) {
|
if ((z2 = onigenc_unicode_unfold2_lookup(codes)) != 0 &&
|
||||||
|
CodePointListValidP(z2)) {
|
||||||
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
||||||
items[n].byte_len = len;
|
items[n].byte_len = len;
|
||||||
items[n].code_len = 1;
|
items[n].code_len = 1;
|
||||||
|
@ -611,7 +618,8 @@ onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
||||||
|
|
||||||
clen = enclen(enc, p, end);
|
clen = enclen(enc, p, end);
|
||||||
len += clen;
|
len += clen;
|
||||||
if ((z2 = onigenc_unicode_unfold3_lookup(codes)) != 0) {
|
if ((z2 = onigenc_unicode_unfold3_lookup(codes)) != 0 &&
|
||||||
|
CodePointListValidP(z2)) {
|
||||||
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
for (i = 0; i < OnigCodePointCount(z2->n); i++) {
|
||||||
items[n].byte_len = len;
|
items[n].byte_len = len;
|
||||||
items[n].code_len = 1;
|
items[n].code_len = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue