Issue #21865 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.2: DONTNEED, 3.3: DONTNEED, 3.4: DONTNEED, 4.0: REQUIRED to 3.2: DONTNEED, 3.3: DONTNEED, 3.4: DONTNEED, 4.0: DONE ruby_4_0 commit:c6d9ba58c50fd9c07023453d71cb55b4b9c36957. ---------------------------------------- Bug #21865: Crash on signal raise https://bugs.ruby-lang.org/issues/21865#change-116345 * Author: dodecadaniel (Daniel Colson) * Status: Closed * ruby -v: 4.0.1 * Backport: 3.2: DONTNEED, 3.3: DONTNEED, 3.4: DONTNEED, 4.0: DONE ---------------------------------------- This crashes on Ruby 4.0 ``` sh $ ruby -e 'loop { File.open("./test.rb", kwarg: true) {} }'& [1] 93542 $ kill -TERM 93542 [BUG] Segmentation fault at 0x000000000000001f ``` Note the `0x1f` (i.e. 15, which is `Signal.list["TERM"]`). While preparing the exception we pass argc=2, with argv containing the signal class and the fixnum for the TERM. https://github.com/ruby/ruby/blob/86dba8cfaeabb3b86df921da24b3243b9ce4ab2a/t... That eventually gets passed through to https://github.com/ruby/ruby/blob/86dba8cfaeabb3b86df921da24b3243b9ce4ab2a/c..., where we set the signal fixnum as `last` and treat it like a hash. But 0x1f is a fixnum, not a hash, so that crashes. `rb_scan_args_keyword_p` returns true in this case even though `last` is not a hash because kw_flag is `RB_SCAN_ARGS_PASS_CALLED_KEYWORDS` (which I think causes it to look at the last frame to see if keywords were passed, rather than checking whether `last` is a hash. I don't think we push any frames in this case, so it's looking at whatever the last frame before the signal happened to be). Should we still check that it's a hash regardless? I believe the bug was introduced in https://github.com/ruby/ruby/commit/64f508ade8c8535b7d3ecdd217886aa52fddd43c. -- https://bugs.ruby-lang.org/