From fef1c152ce4e52b9e4a34dc23aca5b02907ac639 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 19 Jan 2019 13:05:09 +0900 Subject: [PATCH] Fix stack overflow when out of memory As a result of this change, no backtrace information is set for NoMemoryError (`mrb->nomem_err`). Detailes: When generating a backtrace, called `mrb_intern_lit()`, `mrb_str_new_cstr()` and `mrb_obj_iv_set()` function with `exc_debug_info()` function in `src/error.c`. If a `NoMemoryError` exception occurs at this time, the `exc_debug_info()` function will be called again, and in the same way `NoMemoryError` exception raised will result in an infinite loop to occurs stack overflow (and SIGSEGV). --- src/error.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/error.c b/src/error.c index 6674fe7ad..fe193a9a9 100644 --- a/src/error.c +++ b/src/error.c @@ -200,6 +200,7 @@ exc_debug_info(mrb_state *mrb, struct RObject *exc) mrb_callinfo *ci = mrb->c->ci; mrb_code *pc = ci->pc; + if (!exc || exc == mrb->nomem_err) return; if (mrb_obj_iv_defined(mrb, exc, mrb_intern_lit(mrb, "file"))) return; while (ci >= mrb->c->cibase) { mrb_code *err = ci->err;