ruby-changes:50571
From: nobu <ko1@a...>
Date: Sat, 10 Mar 2018 19:36:41 +0900 (JST)
Subject: [ruby-changes:50571] nobu:r62715 (trunk): signal.c: check NUL bytes
nobu 2018-03-10 19:36:35 +0900 (Sat, 10 Mar 2018) New Revision: 62715 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62715 Log: signal.c: check NUL bytes * signal.c (trap_signm): check NUL bytes explicitly before raising "unsupported signal" ArgumentError. Modified files: trunk/signal.c trunk/test/ruby/test_signal.rb Index: signal.c =================================================================== --- signal.c (revision 62714) +++ signal.c (revision 62715) @@ -1206,23 +1206,17 @@ trap_signm(VALUE vsig) https://github.com/ruby/ruby/blob/trunk/signal.c#L1206 int sig = -1; const char *s; - switch (TYPE(vsig)) { - case T_FIXNUM: + if (FIXNUM_P(vsig)) { sig = FIX2INT(vsig); if (sig < 0 || sig >= NSIG) { rb_raise(rb_eArgError, "invalid signal number (%d)", sig); } - break; - - case T_SYMBOL: - vsig = rb_sym2str(vsig); - s = RSTRING_PTR(vsig); - goto str_signal; - - default: - s = StringValuePtr(vsig); - - str_signal: + } + else { + if (RB_SYMBOL_P(vsig)) { + vsig = rb_sym2str(vsig); + } + s = StringValueCStr(vsig); if (strncmp(signame_prefix, s, sizeof(signame_prefix)) == 0) s += 3; sig = signm2signo(s); Index: test/ruby/test_signal.rb =================================================================== --- test/ruby/test_signal.rb (revision 62714) +++ test/ruby/test_signal.rb (revision 62715) @@ -164,6 +164,8 @@ class TestSignal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_signal.rb#L164 assert_raise(ArgumentError) { Signal.trap("XXXXXXXXXX", "SIG_DFL") } assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) { Signal.trap("\u{30eb 30d3 30fc}", "SIG_DFL") } + + assert_raise(ArgumentError) { Signal.trap("EXIT\0") {} } ensure Signal.trap(:INT, oldtrap) if oldtrap end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/