backtrace.c (pack_backtrace_i): avoid infinite loop; ref #6161

When irep->refcnt reaches UINT16_MAX, mrb_irep_incref() raises
exception but the function pack_backtrace_i() is called from
mrb_exc_raise() thus causes the infinite loop problem. So this is a
hack-ish workaround by making irep reference to NULL if refcnt reaches
the maximum count. Probably we will address this issue again to make it
better.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-02-06 22:35:24 +09:00
parent b8e4c4b6ba
commit b67cea4442
+8 -3
View File
@@ -85,10 +85,15 @@ pack_backtrace_i(mrb_state *mrb,
struct mrb_backtrace_location **pptr = (struct mrb_backtrace_location**)data;
struct mrb_backtrace_location *ptr = *pptr;
if (loc->irep) {
mrb_irep_incref(mrb, (mrb_irep*)loc->irep);
}
*ptr = *loc;
if (ptr->irep) {
if (ptr->irep->refcnt == UINT16_MAX) {
ptr->irep = NULL;
}
else {
mrb_irep_incref(mrb, (mrb_irep*)ptr->irep);
}
}
*pptr = ptr+1;
}