diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-03 22:03:59 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-12-03 22:03:59 +0000 |
commit | 0c662b34313699223f08df54c5dcd8c481ff8a95 (patch) | |
tree | d6e0d9ae03e566e6f1b808590f957c20322bf79f | |
parent | ddc4cd4ace2ebd80703faa32f35962762435a3ef (diff) | |
download | ruby-0c662b34313699223f08df54c5dcd8c481ff8a95.tar.gz |
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
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | iseq.c | 12 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 4 |
3 files changed, 17 insertions, 5 deletions
@@ -1,3 +1,9 @@ +Thu Dec 4 06:56:57 2014 Eric Wong <e@80x24.org> + + * 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@ruby-lang.org> * load.c (ruby_require_internal): ignore error detail, just return @@ -79,12 +79,14 @@ iseq_free(void *ptr) 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) { diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index d36cbb0638..38799a841e 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -364,6 +364,10 @@ WARN } 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) |