From 9c927f8c8b6773ac24f2ba404027d5701704331e Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 21 Aug 2017 14:15:31 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- gc.c | 1 + vm.c | 1 + vm_eval.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gc.c b/gc.c index bfd6689f8a..ad83006ea0 100644 --- a/gc.c +++ b/gc.c @@ -4004,6 +4004,7 @@ ruby_stack_length(VALUE **p) 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 diff --git a/vm.c b/vm.c index ea3cf6da3f..1da03c4566 100644 --- a/vm.c +++ b/vm.c @@ -1018,6 +1018,7 @@ invoke_iseq_block_from_c(rb_thread_t *th, const struct rb_captured_block *captur 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; diff --git a/vm_eval.c b/vm_eval.c index 1948c4215b..479cda6da0 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -258,7 +258,7 @@ stack_check(rb_thread_t *th) 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); } }