ruby-changes:47514
From: nobu <ko1@a...>
Date: Mon, 21 Aug 2017 23:15:37 +0900 (JST)
Subject: [ruby-changes:47514] nobu:r59630 (trunk): prevent stack overflow
nobu 2017-08-21 23:15:31 +0900 (Mon, 21 Aug 2017) New Revision: 59630 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59630 Log: prevent stack overflow * gc.c: enable PREVENT_STACK_OVERFLOW. * vm.c (invoke_iseq_block_from_c): prevent stack overflow. * vm_eval.c (stack_check): raise preallocated exception instance. Modified files: trunk/gc.c trunk/vm.c trunk/vm_eval.c Index: vm_eval.c =================================================================== --- vm_eval.c (revision 59629) +++ vm_eval.c (revision 59630) @@ -258,7 +258,7 @@ stack_check(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L258 if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) && rb_threadptr_stack_check(th)) { rb_thread_raised_set(th, RAISED_STACKOVERFLOW); - rb_exc_raise(sysstack_error); + rb_threadptr_stack_overflow(th); } } Index: gc.c =================================================================== --- gc.c (revision 59629) +++ gc.c (revision 59630) @@ -4004,6 +4004,7 @@ ruby_stack_length(VALUE **p) https://github.com/ruby/ruby/blob/trunk/gc.c#L4004 return STACK_LENGTH; } +#define PREVENT_STACK_OVERFLOW 1 #ifndef PREVENT_STACK_OVERFLOW #if !(defined(POSIX_SIGNAL) && defined(SIGSEGV) && defined(HAVE_SIGALTSTACK)) # define PREVENT_STACK_OVERFLOW 1 Index: vm.c =================================================================== --- vm.c (revision 59629) +++ vm.c (revision 59630) @@ -1018,6 +1018,7 @@ invoke_iseq_block_from_c(rb_thread_t *th https://github.com/ruby/ruby/blob/trunk/vm.c#L1018 VALUE *sp = cfp->sp; const rb_callable_method_entry_t *me = th->passed_bmethod_me; th->passed_bmethod_me = NULL; + stack_check(th); CHECK_VM_STACK_OVERFLOW(cfp, argc); cfp->sp = sp + argc; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/