Bug #22240
openProtect against SEGV caused by native extensions using rb_funcall between rb_protect and rb_jump_tag
Description
It's possible for native extensions do something like
int state = 0;
rb_protect(some_func, Qnil, &state);
if (state) {
rb_funcall(self, rb_intern("handler"), 0);
rb_jump_tag(state);
}
If the ruby code in the rb_funcall has a rescue clause it will clear errinfo.
When rb_jump_tag flows to hook_before_rewind with errinfo as Qnil it currently will SEGV.
If I add a check to avoid the SEGV, the process then exits silently.
If a native extension puts us in this state, the original message is gone.
One thing we can do is detect this scenario and fabricate an exception.
I have a PR up with a possible solution for this but am looking for feedback on the exception type and message or alternative suggestions for handling.
I have reproduced this crash as far back as Ruby 3.3.
Updated by rwstauner (Randy Stauner) 5 days ago
Updated by rwstauner (Randy Stauner) about 17 hours ago
So far I have discovered that this bug was possible to encounter with
bootsnap before https://github.com/rails/bootsnap/pull/564
and with
io-event before https://github.com/socketry/io-event/pull/209