Commit ab823852
ab8238525325Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Fix clang-exposed UB in regexp errors and File separator literals
Two latent bugs that gcc happened to tolerate but clang's codegen/layout exposed (CI red, also caught by UBSan):
-
sp_re_default_error_handler passed the regex compiler's stack buffer straight to sp_raise_cls, which stores the pointer and longjmps past that frame -- e.message then read freed stack ("untermin"). Copy the message to a GC string first, mirroring the startup handler.
-
File::SEPARATOR / PATH_SEPARATOR were emitted as bare "/" / ":" literals, not the marker-framed
(&("\xff" "/")[1])form every spinel string uses. sp_str_byte_len/sp_str_concat then read literal[-1] out of bounds (crash under clang). Frame them like ALT_SEPARATOR.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- ab8238525325
- Parent
- f607138b4f61
lib/sp_runtime.hmodifiedView file
library calls sp_re_set_error_handler at startup -- codegen emits the install call after the exception infrastructure is set up. */static void sp_re_default_error_handler(const char *msg) { /* msg points at the regex compiler's stack buffer. sp_raise_cls stores the pointer and longjmps past that frame, leaving it dangling -- copy to a GC-managed string first (mirrors sp_re_startup_error_handler). gcc happened to leave the stack intact; clang reused it, so e.message read garbage (regexp_error_catchable). */ if (msg) { size_t n = strlen(msg); char *buf = sp_str_alloc_raw(n + 1); memcpy(buf, msg, n); buf[n] = 0; msg = buf; } sp_raise_cls("RegexpError", msg);}/* Issue #846: during sp_re_init (before main()'s setjmp scope issrc/codegen_expr.cmodifiedView file
Loading diff…