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

ruby-changes:36588

From: nobu <ko1@a...>
Date: Tue, 2 Dec 2014 04:43:27 +0900 (JST)
Subject: [ruby-changes:36588] nobu:r48669 (trunk): re.c: check if onig_region_copy failed

nobu	2014-12-02 04:43:10 +0900 (Tue, 02 Dec 2014)

  New Revision: 48669

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

  Log:
    re.c: check if onig_region_copy failed
    
    * re.c (CHECK_REGION_COPIED): onig_region_copy() can fail when
      memory exhausted but returns nothing, so check by if allocated.

  Modified files:
    trunk/ChangeLog
    trunk/ext/strscan/strscan.c
    trunk/re.c
Index: re.c
===================================================================
--- re.c	(revision 48668)
+++ re.c	(revision 48669)
@@ -20,6 +20,8 @@ VALUE rb_eRegexpError; https://github.com/ruby/ruby/blob/trunk/re.c#L20
 typedef char onig_errmsg_buffer[ONIG_MAX_ERROR_MESSAGE_LEN];
 #define errcpy(err, msg) strlcpy((err), (msg), ONIG_MAX_ERROR_MESSAGE_LEN)
 
+#define CHECK_REGION_COPIED(regs) \
+    do {if (!(regs)->allocated) rb_memerror();} while (0)
 #define BEG(no) (regs->beg[(no)])
 #define END(no) (regs->end[(no)])
 
@@ -983,6 +985,7 @@ match_init_copy(VALUE obj, VALUE orig) https://github.com/ruby/ruby/blob/trunk/re.c#L985
 
     rm = RMATCH(obj)->rmatch;
     onig_region_copy(&rm->regs, RMATCH_REGS(orig));
+    CHECK_REGION_COPIED(&rm->regs);
 
     if (!RMATCH(orig)->rmatch->char_offset_updated) {
         rm->char_offset_updated = 0;
@@ -1472,6 +1475,7 @@ rb_reg_search0(VALUE re, VALUE str, long https://github.com/ruby/ruby/blob/trunk/re.c#L1475
 	match = match_alloc(rb_cMatch);
 	onig_region_copy(RMATCH_REGS(match), regs);
 	onig_region_free(regs, 0);
+	CHECK_REGION_COPIED(RMATCH_REGS(match));
     }
     else {
 	if (rb_safe_level() >= 3)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48668)
+++ ChangeLog	(revision 48669)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec  2 04:43:08 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* re.c (CHECK_REGION_COPIED): onig_region_copy() can fail when
+	  memory exhausted but returns nothing, so check by if allocated.
+
 Tue Dec  2 02:53:00 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (magic_comment_encoding): enable in ripper, since the
Index: ext/strscan/strscan.c
===================================================================
--- ext/strscan/strscan.c	(revision 48668)
+++ ext/strscan/strscan.c	(revision 48669)
@@ -252,6 +252,7 @@ strscan_init_copy(VALUE vself, VALUE vor https://github.com/ruby/ruby/blob/trunk/ext/strscan/strscan.c#L252
 	self->prev = orig->prev;
 	self->curr = orig->curr;
 	onig_region_copy(&self->regs, &orig->regs);
+	if (self->regs.allocated) rb_memerror();
     }
 
     return vself;

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

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