Skip to content

Commit 04f0de7

Browse files
committed
* error.c, file.c, gc.c, hash.c, thread.c, variable.c, vm_eval.c, bin/erb:
$SAFE=4 is obsolete. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 408b811 commit 04f0de7

File tree

9 files changed

+11
-71
lines changed

9 files changed

+11
-71
lines changed

ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Sun Aug 18 19:32:26 2013 Kazuki Tsujimoto <kazuki@callcc.net>
2+
3+
* error.c, file.c, gc.c, hash.c, thread.c, variable.c, vm_eval.c, bin/erb:
4+
$SAFE=4 is obsolete.
5+
16
Sun Aug 18 14:30:47 2013 Tanaka Akira <akr@fsij.org>
27

38
* process.c (rb_clock_gettime): Rename POSIX_TIME_CLOCK_REALTIME to

bin/erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ERB
7272
require ARGV.req_arg
7373
when '-S' # security level
7474
arg = ARGV.req_arg
75-
raise "invalid safe_level #{arg.dump}" unless arg =~ /^[0-4]$/
75+
raise "invalid safe_level #{arg.dump}" unless arg =~ /^[0-3]$/
7676
safe_level = arg.to_i
7777
when '-T' # trim mode
7878
arg = ARGV.req_arg
@@ -105,7 +105,7 @@ class ERB
105105
-v enable verbose mode
106106
-d set $DEBUG to true
107107
-r library load a library
108-
-S safe_level set $SAFE (0..4)
108+
-S safe_level set $SAFE (0..3)
109109
-E ex[:in] set default external/internal encodings
110110
-U set default encoding to UTF-8.
111111
-T trim_mode specify trim_mode (0..2, -)

error.c

-4
Original file line numberDiff line numberDiff line change
@@ -2030,10 +2030,6 @@ rb_check_frozen(VALUE obj)
20302030
void
20312031
rb_error_untrusted(VALUE obj)
20322032
{
2033-
if (rb_safe_level() >= 4) {
2034-
rb_raise(rb_eSecurityError, "Insecure: can't modify %s",
2035-
rb_obj_classname(obj));
2036-
}
20372033
}
20382034

20392035
#undef rb_check_trusted

file.c

-8
Original file line numberDiff line numberDiff line change
@@ -5428,10 +5428,6 @@ rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level)
54285428
return 0;
54295429
}
54305430

5431-
if (safe_level >= 4) {
5432-
rb_raise(rb_eSecurityError, "loading from non-absolute path %s", f);
5433-
}
5434-
54355431
RB_GC_GUARD(load_path) = rb_get_expanded_load_path();
54365432
if (!load_path) return 0;
54375433

@@ -5493,10 +5489,6 @@ rb_find_file_safe(VALUE path, int safe_level)
54935489
return path;
54945490
}
54955491

5496-
if (safe_level >= 4) {
5497-
rb_raise(rb_eSecurityError, "loading from non-absolute path %s", f);
5498-
}
5499-
55005492
RB_GC_GUARD(load_path) = rb_get_expanded_load_path();
55015493
if (load_path) {
55025494
long i;

gc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4578,7 +4578,7 @@ rb_memerror(void)
45784578
{
45794579
rb_thread_t *th = GET_THREAD();
45804580
if (!nomem_error ||
4581-
(rb_thread_raised_p(th, RAISED_NOMEMORY) && rb_safe_level() < 4)) {
4581+
rb_thread_raised_p(th, RAISED_NOMEMORY)) {
45824582
fprintf(stderr, "[FATAL] failed to allocate memory\n");
45834583
exit(EXIT_FAILURE);
45844584
}

hash.c

-4
Original file line numberDiff line numberDiff line change
@@ -2714,10 +2714,6 @@ env_aset(VALUE obj, VALUE nm, VALUE val)
27142714
{
27152715
char *name, *value;
27162716

2717-
if (rb_safe_level() >= 4) {
2718-
rb_raise(rb_eSecurityError, "can't change environment variable");
2719-
}
2720-
27212717
if (NIL_P(val)) {
27222718
env_delete(obj, nm);
27232719
return Qnil;

thread.c

-25
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,6 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
541541
if (state == TAG_FATAL) {
542542
/* fatal error within this thread, need to stop whole script */
543543
}
544-
else if (th->safe_level >= 4) {
545-
/* Ignore it. Main thread shouldn't be harmed from untrusted thread. */
546-
errinfo = Qnil;
547-
}
548544
else if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
549545
/* exit on main_thread. */
550546
}
@@ -2176,8 +2172,6 @@ rb_thread_kill(VALUE thread)
21762172

21772173
GetThreadPtr(thread, th);
21782174

2179-
if (th != GET_THREAD() && th->safe_level < 4) {
2180-
}
21812175
if (th->to_kill || th->status == THREAD_KILLED) {
21822176
return thread;
21832177
}
@@ -2741,9 +2735,6 @@ rb_thread_local_aref(VALUE thread, ID id)
27412735
st_data_t val;
27422736

27432737
GetThreadPtr(thread, th);
2744-
if (rb_safe_level() >= 4 && th != GET_THREAD()) {
2745-
rb_raise(rb_eSecurityError, "Insecure: thread locals");
2746-
}
27472738
if (!th->local_storage) {
27482739
return Qnil;
27492740
}
@@ -2827,9 +2818,6 @@ rb_thread_local_aset(VALUE thread, ID id, VALUE val)
28272818
rb_thread_t *th;
28282819
GetThreadPtr(thread, th);
28292820

2830-
if (rb_safe_level() >= 4 && th != GET_THREAD()) {
2831-
rb_raise(rb_eSecurityError, "Insecure: can't modify thread locals");
2832-
}
28332821
if (OBJ_FROZEN(thread)) {
28342822
rb_error_frozen("thread locals");
28352823
}
@@ -2898,15 +2886,8 @@ static VALUE
28982886
rb_thread_variable_get(VALUE thread, VALUE key)
28992887
{
29002888
VALUE locals;
2901-
rb_thread_t *th;
29022889
ID id = rb_check_id(&key);
29032890

2904-
GetThreadPtr(thread, th);
2905-
2906-
if (rb_safe_level() >= 4 && th != GET_THREAD()) {
2907-
rb_raise(rb_eSecurityError, "Insecure: can't access thread locals");
2908-
}
2909-
29102891
if (!id) return Qnil;
29112892
locals = rb_ivar_get(thread, id_locals);
29122893
return rb_hash_aref(locals, ID2SYM(id));
@@ -2925,13 +2906,7 @@ static VALUE
29252906
rb_thread_variable_set(VALUE thread, VALUE id, VALUE val)
29262907
{
29272908
VALUE locals;
2928-
rb_thread_t *th;
29292909

2930-
GetThreadPtr(thread, th);
2931-
2932-
if (rb_safe_level() >= 4 && th != GET_THREAD()) {
2933-
rb_raise(rb_eSecurityError, "Insecure: can't modify thread locals");
2934-
}
29352910
if (OBJ_FROZEN(thread)) {
29362911
rb_error_frozen("thread locals");
29372912
}

variable.c

-5
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,6 @@ rb_gvar_set(struct global_entry *entry, VALUE val)
782782
struct trace_data trace;
783783
struct global_variable *var = entry->var;
784784

785-
if (rb_safe_level() >= 4)
786-
rb_raise(rb_eSecurityError, "Insecure: can't change global variable value");
787785
(*var->setter)(val, entry->id, var->data, var);
788786

789787
if (var->trace && !var->block_trace) {
@@ -860,9 +858,6 @@ rb_alias_variable(ID name1, ID name2)
860858
struct global_entry *entry1, *entry2;
861859
st_data_t data1;
862860

863-
if (rb_safe_level() >= 4)
864-
rb_raise(rb_eSecurityError, "Insecure: can't alias global variable");
865-
866861
entry2 = rb_global_entry(name2);
867862
if (!st_lookup(rb_global_tbl, (st_data_t)name1, &data1)) {
868863
entry1 = ALLOC(struct global_entry);

vm_eval.c

+3-22
Original file line numberDiff line numberDiff line change
@@ -1337,16 +1337,7 @@ rb_f_eval(int argc, VALUE *argv, VALUE self)
13371337
int line = 1;
13381338

13391339
rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
1340-
if (rb_safe_level() >= 4) {
1341-
StringValue(src);
1342-
if (!NIL_P(scope) && !OBJ_TAINTED(scope)) {
1343-
rb_raise(rb_eSecurityError,
1344-
"Insecure: can't modify trusted binding");
1345-
}
1346-
}
1347-
else {
1348-
SafeStringValue(src);
1349-
}
1340+
SafeStringValue(src);
13501341
if (argc >= 3) {
13511342
StringValue(vfile);
13521343
}
@@ -1551,12 +1542,7 @@ eval_under(VALUE under, VALUE self, VALUE src, VALUE file, int line)
15511542
if (SPECIAL_CONST_P(self) && !NIL_P(under)) {
15521543
cref->flags |= NODE_FL_CREF_PUSHED_BY_EVAL;
15531544
}
1554-
if (rb_safe_level() >= 4) {
1555-
StringValue(src);
1556-
}
1557-
else {
1558-
SafeStringValue(src);
1559-
}
1545+
SafeStringValue(src);
15601546

15611547
return eval_string_with_cref(self, src, Qnil, cref, file, line);
15621548
}
@@ -1573,12 +1559,7 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
15731559
int line = 1;
15741560

15751561
rb_check_arity(argc, 1, 3);
1576-
if (rb_safe_level() >= 4) {
1577-
StringValue(argv[0]);
1578-
}
1579-
else {
1580-
SafeStringValue(argv[0]);
1581-
}
1562+
SafeStringValue(argv[0]);
15821563
if (argc > 2)
15831564
line = NUM2INT(argv[2]);
15841565
if (argc > 1) {

0 commit comments

Comments
 (0)