ruby-changes:24123
From: nobu <ko1@a...>
Date: Fri, 22 Jun 2012 13:32:52 +0900 (JST)
Subject: [ruby-changes:24123] nobu:r36174 (trunk): error.c: rb_check_copyable
nobu 2012-06-22 13:32:39 +0900 (Fri, 22 Jun 2012) New Revision: 36174 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36174 Log: error.c: rb_check_copyable * error.c (rb_check_copyable): new function, to ensure the target is not frozen and the source is not tainted nor untrusted. Modified files: trunk/ChangeLog trunk/error.c trunk/include/ruby/intern.h Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 36173) +++ include/ruby/intern.h (revision 36174) @@ -251,6 +251,7 @@ } #define rb_check_trusted(obj) rb_check_trusted_inline(obj) #endif +void rb_check_copyable(VALUE obj, VALUE orig); #define OBJ_INIT_COPY(obj, orig) \ ((obj) != (orig) && (rb_obj_init_copy((obj), (orig)), 1)) Index: ChangeLog =================================================================== --- ChangeLog (revision 36173) +++ ChangeLog (revision 36174) @@ -1,3 +1,8 @@ +Fri Jun 22 13:32:33 2012 Nobuyoshi Nakada <nobu@r...> + + * error.c (rb_check_copyable): new function, to ensure the target is + not frozen and the source is not tainted nor untrusted. + Fri Jun 22 05:55:20 2012 Eric Hodel <drbrain@s...> * eval.c (ruby_cleanup): Fixed typo. Patch by Trever Dawe. Index: error.c =================================================================== --- error.c (revision 36173) +++ error.c (revision 36174) @@ -2011,6 +2011,21 @@ } void +rb_check_copyable(VALUE obj, VALUE orig) +{ + if (!FL_ABLE(obj)) return; + rb_check_frozen_internal(obj); + rb_check_trusted_internal(obj); + if (!FL_ABLE(orig)) return; + if ((~RBASIC(obj)->flags & RBASIC(orig)->flags) & (FL_UNTRUSTED|FL_TAINT)) { + if (rb_safe_level() > 0) { + rb_raise(rb_eSecurityError, "Insecure: can't modify %"PRIsVALUE, + RBASIC(obj)->klass); + } + } +} + +void Init_syserr(void) { rb_eNOERROR = set_syserr(0, "NOERROR"); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/