[前][次][番号順一覧][スレッド一覧]

ruby-changes:42016

From: nobu <ko1@a...>
Date: Sat, 12 Mar 2016 10:15:35 +0900 (JST)
Subject: [ruby-changes:42016] nobu:r54090 (trunk): unicode.c: boundary check

nobu	2016-03-12 10:15:31 +0900 (Sat, 12 Mar 2016)

  New Revision: 54090

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54090

  Log:
    unicode.c: boundary check
    
    * enc/unicode.c (CodePointListValidP): add pathological boundary
      check, for gcc 4.9.

  Modified files:
    trunk/enc/unicode.c
Index: enc/unicode.c
===================================================================
--- enc/unicode.c	(revision 54089)
+++ enc/unicode.c	(revision 54090)
@@ -431,6 +431,8 @@ onigenc_unicode_apply_all_case_fold(Onig https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L431
   return 0;
 }
 
+#define CodePointListValidP(x) (OnigCodePointCount((x)->n) < numberof((x)->code))
+
 extern int
 onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
     OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end,
@@ -483,7 +485,8 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L485
       n++;
 
       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++) {
 	  if (to->code[i] != orig_code) {
 	    items[n].byte_len = len;
@@ -521,7 +524,8 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L524
 	  }
 	}
 
-	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++) {
 	    if (z2->code[i] == code) continue;
 
@@ -546,7 +550,8 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L550
 	  }
 	}
 
-	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++) {
 	    if (z2->code[i] == code) continue;
 
@@ -563,7 +568,8 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L568
     }
   }
   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++) {
 	items[n].byte_len = len;
 	items[n].code_len = 1;
@@ -590,7 +596,8 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L596
 
       clen = enclen(enc, p, end);
       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++) {
 	  items[n].byte_len = len;
 	  items[n].code_len = 1;
@@ -611,7 +618,8 @@ onigenc_unicode_get_case_fold_codes_by_s https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L618
 
 	clen = enclen(enc, p, end);
 	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++) {
 	    items[n].byte_len = len;
 	    items[n].code_len = 1;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]