From fd9847c808c421a201ae574d93f6d0ea36d9ec63 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 15 Jul 2018 00:58:37 +0000 Subject: Mwrap.dump: do not segfault on invalid IO arg Users may screw up ordering of arguments :x --- ext/mwrap/mwrap.c | 1 + test/test_mwrap.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c index 3f59f11..c160e33 100644 --- a/ext/mwrap/mwrap.c +++ b/ext/mwrap/mwrap.c @@ -346,6 +346,7 @@ static VALUE mwrap_dump(int argc, VALUE * argv, VALUE mod) io = *((VALUE *)dlsym(RTLD_DEFAULT, "rb_stderr")); a.min = NIL_P(min) ? 0 : NUM2SIZET(min); + io = rb_io_get_io(io); io = rb_io_get_write_io(io); GetOpenFile(io, fptr); a.fp = rb_io_stdio_file(fptr); diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb index 3de9c1b..d76e4da 100644 --- a/test/test_mwrap.rb +++ b/test/test_mwrap.rb @@ -155,4 +155,8 @@ class TestMwrap < Test::Unit::TestCase warn Benchmark::Tms::CAPTION warn r.read end if ENV['BENCHMARK'] + + def test_mwrap_dump_check + assert_raise(TypeError) { Mwrap.dump(:bogus) } + end end -- cgit v1.2.3-24-ge0c7