From 8dd2435877fae9b13b107cb306c0f4d723451f20 Mon Sep 17 00:00:00 2001 From: eregon Date: Thu, 31 Mar 2016 16:14:52 +0000 Subject: [PATCH] * thread.c (update_coverage): Do not track coverage in loaded files after Coverage.result. Avoids out-of-bounds access. [Bug #12237] * ext/coverage/coverage.c (coverage_clear_result_i): document. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ ext/coverage/coverage.c | 1 + thread.c | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ceb86c30b8..0fca5a1013 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Apr 1 01:13:55 2016 Benoit Daloze + + * thread.c (update_coverage): Do not track coverage in loaded files + after Coverage.result. Avoids out-of-bounds access. [Bug #12237] + + * ext/coverage/coverage.c (coverage_clear_result_i): document. + Thu Mar 31 19:16:16 2016 Koichi Sasada * gc.c: need to set initial value of GC_HEAP_FREE_SLOTS_GOAL_RATIO. diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c index 0c7755bc6d..f621280ca6 100644 --- a/ext/coverage/coverage.c +++ b/ext/coverage/coverage.c @@ -32,6 +32,7 @@ rb_coverage_start(VALUE klass) return Qnil; } +/* Make coverage arrays empty so old covered files are no longer tracked. */ static int coverage_clear_result_i(st_data_t key, st_data_t val, st_data_t h) { diff --git a/thread.c b/thread.c index 9d1e3fec60..a68651b2e1 100644 --- a/thread.c +++ b/thread.c @@ -4777,7 +4777,7 @@ update_coverage(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klas if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) { long line = rb_sourceline() - 1; long count; - if (RARRAY_AREF(coverage, line) == Qnil) { + if (line >= RARRAY_LEN(coverage)) { /* no longer tracked */ return; } count = FIX2LONG(RARRAY_AREF(coverage, line)) + 1;