mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
process.c: null bytes
* process.c (rlimit_type_by_sym): prohibit null bytes in key names. [ruby-core:82033] [Bug #13744] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a39ad0f065
commit
1e84c8343f
2 changed files with 23 additions and 12 deletions
31
process.c
31
process.c
|
@ -1817,7 +1817,7 @@ check_exec_options_i(st_data_t st_key, st_data_t st_val, st_data_t arg)
|
||||||
VALUE execarg_obj = (VALUE)arg;
|
VALUE execarg_obj = (VALUE)arg;
|
||||||
if (rb_execarg_addopt(execarg_obj, key, val) != ST_CONTINUE) {
|
if (rb_execarg_addopt(execarg_obj, key, val) != ST_CONTINUE) {
|
||||||
if (SYMBOL_P(key))
|
if (SYMBOL_P(key))
|
||||||
rb_raise(rb_eArgError, "wrong exec option symbol: %"PRIsVALUE,
|
rb_raise(rb_eArgError, "wrong exec option symbol: % "PRIsVALUE,
|
||||||
key);
|
key);
|
||||||
rb_raise(rb_eArgError, "wrong exec option");
|
rb_raise(rb_eArgError, "wrong exec option");
|
||||||
}
|
}
|
||||||
|
@ -4678,13 +4678,13 @@ proc_setpriority(VALUE obj, VALUE which, VALUE who, VALUE prio)
|
||||||
|
|
||||||
#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
|
#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
|
||||||
static int
|
static int
|
||||||
rlimit_resource_name2int(const char *name, int casetype)
|
rlimit_resource_name2int(const char *name, long len, int casetype)
|
||||||
{
|
{
|
||||||
int resource;
|
int resource;
|
||||||
const char *p;
|
const char *p;
|
||||||
#define RESCHECK(r) \
|
#define RESCHECK(r) \
|
||||||
do { \
|
do { \
|
||||||
if (STRCASECMP(name, #r) == 0) { \
|
if (len == rb_strlen_lit(#r) && STRCASECMP(name, #r) == 0) { \
|
||||||
resource = RLIMIT_##r; \
|
resource = RLIMIT_##r; \
|
||||||
goto found; \
|
goto found; \
|
||||||
} \
|
} \
|
||||||
|
@ -4787,25 +4787,29 @@ rlimit_resource_name2int(const char *name, int casetype)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rlimit_type_by_hname(const char *name)
|
rlimit_type_by_hname(const char *name, long len)
|
||||||
{
|
{
|
||||||
return rlimit_resource_name2int(name, 0);
|
return rlimit_resource_name2int(name, len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rlimit_type_by_lname(const char *name)
|
rlimit_type_by_lname(const char *name, long len)
|
||||||
{
|
{
|
||||||
return rlimit_resource_name2int(name, 1);
|
return rlimit_resource_name2int(name, len, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rlimit_type_by_sym(VALUE key)
|
rlimit_type_by_sym(VALUE key)
|
||||||
{
|
{
|
||||||
const char *rname = RSTRING_PTR(rb_sym2str(key));
|
VALUE name = rb_sym2str(key);
|
||||||
|
const char *rname = RSTRING_PTR(name);
|
||||||
|
long len = RSTRING_LEN(name);
|
||||||
int rtype = -1;
|
int rtype = -1;
|
||||||
|
static const char prefix[] = "rlimit_";
|
||||||
|
enum {prefix_len = sizeof(prefix)-1};
|
||||||
|
|
||||||
if (strncmp("rlimit_", rname, 7) == 0) {
|
if (len > prefix_len && strncmp(prefix, rname, prefix_len) == 0) {
|
||||||
rtype = rlimit_type_by_lname(rname + 7);
|
rtype = rlimit_type_by_lname(rname + prefix_len, len - prefix_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_GC_GUARD(key);
|
RB_GC_GUARD(key);
|
||||||
|
@ -4816,6 +4820,7 @@ static int
|
||||||
rlimit_resource_type(VALUE rtype)
|
rlimit_resource_type(VALUE rtype)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
long len;
|
||||||
VALUE v;
|
VALUE v;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -4823,6 +4828,7 @@ rlimit_resource_type(VALUE rtype)
|
||||||
case T_SYMBOL:
|
case T_SYMBOL:
|
||||||
v = rb_sym2str(rtype);
|
v = rb_sym2str(rtype);
|
||||||
name = RSTRING_PTR(v);
|
name = RSTRING_PTR(v);
|
||||||
|
len = RSTRING_LEN(v);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -4831,6 +4837,7 @@ rlimit_resource_type(VALUE rtype)
|
||||||
rtype = v;
|
rtype = v;
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
name = StringValueCStr(rtype);
|
name = StringValueCStr(rtype);
|
||||||
|
len = RSTRING_LEN(rtype);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
@ -4840,11 +4847,11 @@ rlimit_resource_type(VALUE rtype)
|
||||||
return NUM2INT(rtype);
|
return NUM2INT(rtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = rlimit_type_by_hname(name);
|
r = rlimit_type_by_hname(name, len);
|
||||||
if (r != -1)
|
if (r != -1)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
rb_raise(rb_eArgError, "invalid resource name: %"PRIsVALUE, rtype);
|
rb_raise(rb_eArgError, "invalid resource name: % "PRIsVALUE, rtype);
|
||||||
|
|
||||||
UNREACHABLE;
|
UNREACHABLE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,6 +254,10 @@ class TestProcess < Test::Unit::TestCase
|
||||||
system("#{RUBY}", '-e', 'exit', :rlimit_bogus => 123)
|
system("#{RUBY}", '-e', 'exit', :rlimit_bogus => 123)
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
assert_raise(ArgumentError, /rlimit_cpu/) {
|
||||||
|
system(RUBY, '-e', 'exit', "rlimit_cpu\0".to_sym => 3600)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
MANDATORY_ENVS = %w[RUBYLIB]
|
MANDATORY_ENVS = %w[RUBYLIB]
|
||||||
|
|
Loading…
Reference in a new issue