From f433d710d0ab3b367cc4a851cdfb81c5405bb7f8 Mon Sep 17 00:00:00 2001 From: shugo Date: Wed, 13 Aug 2008 07:25:05 +0000 Subject: * object.c (rb_obj_untrusted): new method Object#untrusted?. (rb_obj_untrust): new method Object#untrust. (rb_obj_trust): new method Object#trust. * array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c, string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c, ruby.c, marshal.c: fixes for Object#untrusted?. * test/ruby/test_module.rb, test/ruby/test_array.rb, test/ruby/test_object.rb, test/ruby/test_string.rb, test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for Object#untrusted?. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- marshal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'marshal.c') diff --git a/marshal.c b/marshal.c index b01d2de201..676f4f8eef 100644 --- a/marshal.c +++ b/marshal.c @@ -137,6 +137,7 @@ struct dump_arg { st_table *symbols; st_table *data; int taint; + int untrust; st_table *compat_tbl; VALUE wrapper; st_table *encodings; @@ -192,6 +193,7 @@ w_nbyte(const char *s, int n, struct dump_arg *arg) rb_str_buf_cat(buf, s, n); if (arg->dest && RSTRING_LEN(buf) >= BUFSIZ) { if (arg->taint) OBJ_TAINT(buf); + if (arg->untrust) OBJ_UNTRUST(buf); rb_io_write(arg->dest, buf); rb_str_resize(buf, 0); } @@ -581,6 +583,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit) } else { if (OBJ_TAINTED(obj)) arg->taint = Qtrue; + if (OBJ_UNTRUSTED(obj)) arg->untrust = Qtrue; if (rb_respond_to(obj, s_mdump)) { volatile VALUE v; @@ -809,6 +812,9 @@ dump_ensure(struct dump_arg *arg) if (arg->taint) { OBJ_TAINT(arg->str); } + if (arg->untrust) { + OBJ_UNTRUST(arg->str); + } return 0; } @@ -878,6 +884,7 @@ marshal_dump(int argc, VALUE *argv) arg.symbols = st_init_numtable(); arg.data = st_init_numtable(); arg.taint = Qfalse; + arg.untrust = Qfalse; arg.compat_tbl = st_init_numtable(); arg.wrapper = Data_Wrap_Struct(rb_cData, mark_dump_arg, 0, &arg); arg.encodings = 0; @@ -900,6 +907,7 @@ struct load_arg { VALUE data; VALUE proc; int taint; + int untrust; st_table *compat_tbl; VALUE compat_tbl_wrapper; }; @@ -1014,6 +1022,7 @@ r_bytes0(long len, struct load_arg *arg) StringValue(str); if (RSTRING_LEN(str) != len) goto too_short; if (OBJ_TAINTED(str)) arg->taint = Qtrue; + if (OBJ_UNTRUSTED(str)) arg->untrust = Qtrue; } return str; } @@ -1084,6 +1093,11 @@ r_entry(VALUE v, struct load_arg *arg) if ((VALUE)real_obj != Qundef) OBJ_TAINT((VALUE)real_obj); } + if (arg->untrust) { + OBJ_UNTRUST(v); + if ((VALUE)real_obj != Qundef) + OBJ_UNTRUST((VALUE)real_obj); + } return v; } -- cgit v1.2.3