diff options
| author | nagachika <nagachika@ruby-lang.org> | 2025-01-11 15:30:06 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2025-01-11 15:30:06 +0900 |
| commit | f150d67b7d389eb88e0cd13694d3529895d55579 (patch) | |
| tree | 8062d3af8f5415435610e9bed2f2ba521019475f | |
| parent | 4e59c10646cf012d457da99ad258b0e6a3e42132 (diff) | |
merge revision(s) 8034e9c3d001ca3dff124ab42972684eac8af2ae: [Backport #20995]
[Bug #20995] Protect `IO.popen` block from exiting by exception
| -rw-r--r-- | io.c | 2 | ||||
| -rw-r--r-- | test/ruby/test_process.rb | 30 | ||||
| -rw-r--r-- | version.h | 2 |
3 files changed, 24 insertions, 10 deletions
@@ -7985,7 +7985,7 @@ popen_finish(VALUE port, VALUE klass) if (NIL_P(port)) { /* child */ if (rb_block_given_p()) { - rb_yield(Qnil); + rb_protect(rb_yield, Qnil, NULL); rb_io_flush(rb_ractor_stdout()); rb_io_flush(rb_ractor_stderr()); _exit(0); diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index 07407a7d2f..f48c4982c2 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -905,15 +905,29 @@ class TestProcess < Test::Unit::TestCase } end - def test_popen_fork - IO.popen("-") {|io| - if !io - puts "fooo" - else - assert_equal("fooo\n", io.read) + if Process.respond_to?(:fork) + def test_popen_fork + IO.popen("-") do |io| + if !io + puts "fooo" + else + assert_equal("fooo\n", io.read) + end end - } - rescue NotImplementedError + end + + def test_popen_fork_ensure + IO.popen("-") do |io| + if !io + STDERR.reopen(STDOUT) + raise "fooo" + else + assert_empty io.read + end + end + rescue RuntimeError + abort "[Bug #20995] should not reach here" + end end def test_fd_inheritance @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 6 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 247 +#define RUBY_PATCHLEVEL 248 #include "ruby/version.h" #include "ruby/internal/abi.h" |
