Skip to content

Commit 083c5f0

Browse files
committed
Check stack overflow in recursive glob_helper [Bug #17162]
1 parent a5b4b80 commit 083c5f0

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

dir.c

+2
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,8 @@ glob_helper(
22742274
int escape = !(flags & FNM_NOESCAPE);
22752275
size_t pathlen = baselen + namelen;
22762276

2277+
rb_check_stack_overflow();
2278+
22772279
for (cur = beg; cur < end; ++cur) {
22782280
struct glob_pattern *p = *cur;
22792281
if (p->type == RECURSIVE) {

internal/vm.h

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ VALUE rb_yield_force_blockarg(VALUE values);
8080
VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
8181
rb_block_call_func_t bl_proc, int min_argc, int max_argc,
8282
VALUE data2);
83+
void rb_check_stack_overflow(void);
8384

8485
/* vm_insnhelper.c */
8586
VALUE rb_equal_opt(VALUE obj1, VALUE obj2);

vm_eval.c

+10
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ stack_check(rb_execution_context_t *ec)
302302

303303
#ifndef MJIT_HEADER
304304

305+
void
306+
rb_check_stack_overflow(void)
307+
{
308+
#ifndef RB_THREAD_LOCAL_SPECIFIER
309+
if (!ruby_current_ec_key) return;
310+
#endif
311+
rb_execution_context_t *ec = GET_EC();
312+
if (ec) stack_check(ec);
313+
}
314+
305315
static inline const rb_callable_method_entry_t *rb_search_method_entry(VALUE recv, ID mid);
306316
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);
307317

0 commit comments

Comments
 (0)