[前][次][番号順一覧][スレッド一覧]

ruby-changes:64852

From: Nobuyoshi <ko1@a...>
Date: Wed, 13 Jan 2021 12:16:22 +0900 (JST)
Subject: [ruby-changes:64852] 083c5f08ec (master): Check stack overflow in recursive glob_helper [Bug #17162]

https://git.ruby-lang.org/ruby.git/commit/?id=083c5f08ec

From 083c5f08ec4e95c9b75810d46f933928327a5ab3 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 10 Dec 2020 22:00:11 +0900
Subject: Check stack overflow in recursive glob_helper [Bug #17162]


diff --git a/dir.c b/dir.c
index 48c9eae..fc2c811 100644
--- a/dir.c
+++ b/dir.c
@@ -2274,6 +2274,8 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L2274
     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 a0e067d..80f2c79 100644
--- a/internal/vm.h
+++ b/internal/vm.h
@@ -80,6 +80,7 @@ VALUE rb_yield_force_blockarg(VALUE values); https://github.com/ruby/ruby/blob/trunk/internal/vm.h#L80
 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);
diff --git a/vm_eval.c b/vm_eval.c
index f9e7356..8eb1d5c 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -302,6 +302,16 @@ stack_check(rb_execution_context_t *ec) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L302
 
 #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);
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]