Skip to content

Commit

Permalink
Read errno before calling rb_io_path()
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
XrXr committed Nov 27, 2024
1 parent 3ffc714 commit 0ba400b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ext/io/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ba400b

Please sign in to comment.