Skip to content

Commit 0ba400b

Browse files
committed
Read errno before calling rb_io_path()
Possible fix for recent crashes seen on CI. [BUG] rb_sys_fail_str(<STDIN>) - 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.)
1 parent 3ffc714 commit 0ba400b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ext/io/console/console.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ io_get_write_io_fallback(VALUE io)
125125
#define rb_io_get_write_io io_get_write_io_fallback
126126
#endif
127127

128-
#define sys_fail(io) rb_sys_fail_str(rb_io_path(io))
128+
#define sys_fail(io) do { \
129+
int err = errno; \
130+
rb_syserr_fail_str(err, rb_io_path(io)); \
131+
} while (0)
129132

130133
#ifndef HAVE_RB_F_SEND
131134
#ifndef RB_PASS_CALLED_KEYWORDS

0 commit comments

Comments
 (0)