From c41af37ee64e4fec5f09916485123e8f9ec002cb Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 26 Nov 2024 18:35:34 -0500 Subject: [PATCH] [ruby/io-console] Read errno before calling rb_io_path() Possible fix for recent crashes seen on CI. [BUG] rb_sys_fail_str() - errno == 0 rb_io_path() calls rb_obj_dup(), which could call initialize_dup in Ruby and clobber errno before rb_sys_fail_str() gets to read errno. So save it out first. (Using separate statements because order of evaluation in function call list is unspecified, and order is important here.) https://github.com/ruby/io-console/commit/0ba400b5e7 --- ext/io/console/console.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 77c5c695a1..4475953af0 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -125,7 +125,10 @@ io_get_write_io_fallback(VALUE io) #define rb_io_get_write_io io_get_write_io_fallback #endif -#define sys_fail(io) rb_sys_fail_str(rb_io_path(io)) +#define sys_fail(io) do { \ + int err = errno; \ + rb_syserr_fail_str(err, rb_io_path(io)); \ +} while (0) #ifndef HAVE_RB_F_SEND #ifndef RB_PASS_CALLED_KEYWORDS