ruby-changes:36623
From: normal <ko1@a...>
Date: Thu, 4 Dec 2014 07:04:15 +0900 (JST)
Subject: [ruby-changes:36623] normal:r48704 (trunk): iseq.c: avoid segfault on incomplete iseq
normal 2014-12-04 07:03:59 +0900 (Thu, 04 Dec 2014) New Revision: 48704 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48704 Log: iseq.c: avoid segfault on incomplete iseq Compile failures will trigger iseq_free before iseq->callinfo_entries are allocated at all. * iseq.c (iseq_free): avoid segfault on incomplete iseq * test/ruby/test_syntax.rb (test_invalid_next): new test for syntax error, not segfault Modified files: trunk/ChangeLog trunk/iseq.c trunk/test/ruby/test_syntax.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48703) +++ ChangeLog (revision 48704) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Dec 4 06:56:57 2014 Eric Wong <e@8...> + + * iseq.c (iseq_free): avoid segfault on incomplete iseq + * test/ruby/test_syntax.rb (test_invalid_next): new test + for syntax error, not segfault + Thu Dec 4 04:20:34 2014 Nobuyoshi Nakada <nobu@r...> * load.c (ruby_require_internal): ignore error detail, just return Index: iseq.c =================================================================== --- iseq.c (revision 48703) +++ iseq.c (revision 48704) @@ -79,12 +79,14 @@ iseq_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/iseq.c#L79 RUBY_FREE_UNLESS_NULL(iseq->line_info_table); RUBY_FREE_UNLESS_NULL(iseq->local_table); RUBY_FREE_UNLESS_NULL(iseq->is_entries); - for (i=0; i<iseq->callinfo_size; i++) { - /* TODO: revisit callinfo data structure */ - rb_call_info_kw_arg_t *kw_arg = iseq->callinfo_entries[i].kw_arg; - RUBY_FREE_UNLESS_NULL(kw_arg); + if (iseq->callinfo_entries) { + for (i=0; i<iseq->callinfo_size; i++) { + /* TODO: revisit callinfo data structure */ + rb_call_info_kw_arg_t *kw_arg = iseq->callinfo_entries[i].kw_arg; + RUBY_FREE_UNLESS_NULL(kw_arg); + } + RUBY_FREE_UNLESS_NULL(iseq->callinfo_entries); } - RUBY_FREE_UNLESS_NULL(iseq->callinfo_entries); RUBY_FREE_UNLESS_NULL(iseq->catch_table); RUBY_FREE_UNLESS_NULL(iseq->param.opt_table); if (iseq->param.keyword != NULL) { Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 48703) +++ test/ruby/test_syntax.rb (revision 48704) @@ -364,6 +364,10 @@ WARN https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L364 } end + def test_invalid_next + assert_syntax_error("def m; next; end", /Invalid next/) + end + def test_lambda_with_space feature6390 = '[ruby-dev:45605]' assert_valid_syntax("-> (x, y) {}", __FILE__, feature6390) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/