зеркало из https://github.com/github/ruby.git
signal.c: check NUL bytes
* signal.c (trap_signm): check NUL bytes explicitly before raising "unsupported signal" ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e28760adff
Коммит
dcb28f0da5
20
signal.c
20
signal.c
|
@ -1206,23 +1206,17 @@ trap_signm(VALUE vsig)
|
|||
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);
|
||||
|
|
|
@ -164,6 +164,8 @@ class TestSignal < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче