mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
3f321f09bc
compile_error is the chokepoint for all regex-compile errors; mrb_raisef longjmps out of re_compile, abandoning the stack-local re_compiler struct. Three connected bugs: 1. Memory leak: c->code and c->classes (grown by emit/add_class via mrb_realloc) were never freed before raising, leaking on any compile error like /[/. c->stripped was already cleaned up here for the same reason; the other two buffers were missed. 2. Use-after-free: c->src aliases c->stripped when RE_FLAG_EXTENDED is set, but the original code freed c->stripped before passing c->src to mrb_raisef's "%s" formatter. Format the message into an mrb_value first (mruby's GC-managed string survives the longjmp), then free, then raise. 3. Heap-buffer-overflow: strip_extended returns a non-NUL-terminated buffer of size len. Even with format-before-free, "%s" called strlen and read past the buffer end. Use mruby's %l directive which takes an explicit (char*, size_t) and avoids strlen. Reported by OSS-Fuzz (clusterfuzz testcase 5394267353972736). Co-authored-by: Claude <noreply@anthropic.com>