aboutsummaryrefslogtreecommitdiffstats
path: root/re.c
diff options
context:
space:
mode:
authorrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-06 06:14:17 +0000
committerrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-06 06:14:17 +0000
commita2b27485c1cb4014e41c366e6447382f414360ba (patch)
tree3ae1d5e5113a1ba19f6235d99991bb7b52e833f1 /re.c
parent88311025872a66e746f552d94df23b1c1f2a06e7 (diff)
downloadruby-a2b27485c1cb4014e41c366e6447382f414360ba.tar.gz
re.c: check that MatchData is initialized
Follow r16757 ("* re.c: fix SEGV by Regexp.allocate.names, Match.allocate.names, etc.", 2008-06-02). Don't do null dereference if MatchData#hash or #== is called against an uninitialized instance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/re.c b/re.c
index 9fec950ed9..069a9bc15d 100644
--- a/re.c
+++ b/re.c
@@ -2948,8 +2948,10 @@ static VALUE
match_hash(VALUE match)
{
const struct re_registers *regs;
- st_index_t hashval = rb_hash_start(rb_str_hash(RMATCH(match)->str));
+ st_index_t hashval;
+ match_check(match);
+ hashval = rb_hash_start(rb_str_hash(RMATCH(match)->str));
hashval = rb_hash_uint(hashval, reg_hash(RMATCH(match)->regexp));
regs = RMATCH_REGS(match);
hashval = rb_hash_uint(hashval, regs->num_regs);
@@ -2974,6 +2976,7 @@ match_equal(VALUE match1, VALUE match2)
const struct re_registers *regs1, *regs2;
if (match1 == match2) return Qtrue;
if (!RB_TYPE_P(match2, T_MATCH)) return Qfalse;
+ if (!RMATCH(match1)->regexp || !RMATCH(match2)->regexp) return Qfalse;
if (!rb_str_equal(RMATCH(match1)->str, RMATCH(match2)->str)) return Qfalse;
if (!rb_reg_equal(RMATCH(match1)->regexp, RMATCH(match2)->regexp)) return Qfalse;
regs1 = RMATCH_REGS(match1);