diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-12-10 22:00:11 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-01-13 12:16:00 +0900 |
commit | 083c5f08ec4e95c9b75810d46f933928327a5ab3 (patch) | |
tree | 2290428c880e25479df7479f7bbf457ef93abe96 | |
parent | a5b4b806de3b130348a92aa3306fbb9318efb762 (diff) | |
download | ruby-083c5f08ec4e95c9b75810d46f933928327a5ab3.tar.gz |
Check stack overflow in recursive glob_helper [Bug #17162]
-rw-r--r-- | dir.c | 2 | ||||
-rw-r--r-- | internal/vm.h | 1 | ||||
-rw-r--r-- | vm_eval.c | 10 |
3 files changed, 13 insertions, 0 deletions
@@ -2274,6 +2274,8 @@ glob_helper( int escape = !(flags & FNM_NOESCAPE); size_t pathlen = baselen + namelen; + rb_check_stack_overflow(); + for (cur = beg; cur < end; ++cur) { struct glob_pattern *p = *cur; if (p->type == RECURSIVE) { diff --git a/internal/vm.h b/internal/vm.h index a0e067d40c..80f2c792a3 100644 --- a/internal/vm.h +++ b/internal/vm.h @@ -80,6 +80,7 @@ VALUE rb_yield_force_blockarg(VALUE values); VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, int min_argc, int max_argc, VALUE data2); +void rb_check_stack_overflow(void); /* vm_insnhelper.c */ VALUE rb_equal_opt(VALUE obj1, VALUE obj2); @@ -302,6 +302,16 @@ stack_check(rb_execution_context_t *ec) #ifndef MJIT_HEADER +void +rb_check_stack_overflow(void) +{ +#ifndef RB_THREAD_LOCAL_SPECIFIER + if (!ruby_current_ec_key) return; +#endif + rb_execution_context_t *ec = GET_EC(); + if (ec) stack_check(ec); +} + static inline const rb_callable_method_entry_t *rb_search_method_entry(VALUE recv, ID mid); static inline enum method_missing_reason rb_method_call_status(rb_execution_context_t *ec, const rb_callable_method_entry_t *me, call_type scope, VALUE self); |