ruby.c: reject NUL in $0
* ruby.c (ruby_setproctitle): raise if the argument contains NUL char. process title is a NUL-terminated string. [ruby-core:82425] [Bug #13829] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
42c98194b3
commit
f16f0441d6
14
ruby.c
14
ruby.c
@ -2052,6 +2052,8 @@ proc_argv0(VALUE process)
|
|||||||
return rb_orig_progname;
|
return rb_orig_progname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE ruby_setproctitle(VALUE title);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* Process.setproctitle(string) -> string
|
* Process.setproctitle(string) -> string
|
||||||
@ -2072,10 +2074,14 @@ proc_argv0(VALUE process)
|
|||||||
static VALUE
|
static VALUE
|
||||||
proc_setproctitle(VALUE process, VALUE title)
|
proc_setproctitle(VALUE process, VALUE title)
|
||||||
{
|
{
|
||||||
StringValue(title);
|
return ruby_setproctitle(title);
|
||||||
|
}
|
||||||
setproctitle("%.*s", RSTRING_LENINT(title), RSTRING_PTR(title));
|
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
ruby_setproctitle(VALUE title)
|
||||||
|
{
|
||||||
|
const char *ptr = StringValueCStr(title);
|
||||||
|
setproctitle("%.*s", RSTRING_LENINT(title), ptr);
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2085,7 +2091,7 @@ set_arg0(VALUE val, ID id)
|
|||||||
if (origarg.argv == 0)
|
if (origarg.argv == 0)
|
||||||
rb_raise(rb_eRuntimeError, "$0 not initialized");
|
rb_raise(rb_eRuntimeError, "$0 not initialized");
|
||||||
|
|
||||||
rb_progname = rb_str_new_frozen(proc_setproctitle(rb_mProcess, val));
|
rb_progname = rb_str_new_frozen(ruby_setproctitle(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline VALUE
|
static inline VALUE
|
||||||
|
@ -549,6 +549,13 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||||||
def test_setproctitle
|
def test_setproctitle
|
||||||
skip "platform dependent feature" unless defined?(PSCMD) and PSCMD
|
skip "platform dependent feature" unless defined?(PSCMD) and PSCMD
|
||||||
|
|
||||||
|
assert_separately([], "#{<<-"{#"}\n#{<<-'};'}")
|
||||||
|
{#
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
Process.setproctitle("hello\0")
|
||||||
|
end
|
||||||
|
};
|
||||||
|
|
||||||
with_tmpchdir do
|
with_tmpchdir do
|
||||||
write_file("test-script", "$_0 = $0.dup; Process.setproctitle('hello world'); $0 == $_0 or Process.setproctitle('$0 changed!'); sleep 60")
|
write_file("test-script", "$_0 = $0.dup; Process.setproctitle('hello world'); $0 == $_0 or Process.setproctitle('$0 changed!'); sleep 60")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user