diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-01 19:43:10 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-01 19:43:10 +0000 |
commit | 4d63c8503100b3683ea4eee14a39bbdee3d04c20 (patch) | |
tree | 4f92440094be7823043b284f2c1adebee2c05c4e | |
parent | 11dc42c20ca3cf3be6003fa303eb5649c00ab411 (diff) |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/strscan/strscan.c | 1 | ||||
-rw-r--r-- | re.c | 4 |
3 files changed, 10 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Tue Dec 2 04:43:08 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@ruby-lang.org> * parse.y (magic_comment_encoding): enable in ripper, since the diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c index acb7c61230..780cda08b1 100644 --- a/ext/strscan/strscan.c +++ b/ext/strscan/strscan.c @@ -252,6 +252,7 @@ strscan_init_copy(VALUE vself, VALUE vorig) self->prev = orig->prev; self->curr = orig->curr; onig_region_copy(&self->regs, &orig->regs); + if (self->regs.allocated) rb_memerror(); } return vself; @@ -20,6 +20,8 @@ VALUE rb_eRegexpError; 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) 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 pos, int reverse, int set_backref_str) 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) |