ruby-changes:16428
From: nobu <ko1@a...>
Date: Thu, 24 Jun 2010 05:45:17 +0900 (JST)
Subject: [ruby-changes:16428] Ruby:r28413 (trunk, ruby_1_9_2): * marshal.c (struct dump_arg, struct load_arg): merge taint and
nobu 2010-06-24 05:44:44 +0900 (Thu, 24 Jun 2010) New Revision: 28413 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28413 Log: * marshal.c (struct dump_arg, struct load_arg): merge taint and untrust flags into infection as bit flags. * marshal.c (w_nbyte, clear_dump_arg): infect the buffer as soon as appending, because it might have been finalized already at exit. based on a patch by Tomoyuki Chikanaga at [ruby-dev:41672]. [Bug #3463] Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/marshal.c branches/ruby_1_9_2/version.h trunk/ChangeLog trunk/marshal.c Index: ChangeLog =================================================================== --- ChangeLog (revision 28412) +++ ChangeLog (revision 28413) @@ -1,3 +1,13 @@ +Thu Jun 24 05:44:27 2010 Nobuyoshi Nakada <nobu@r...> + + * marshal.c (struct dump_arg, struct load_arg): merge taint and + untrust flags into infection as bit flags. + + * marshal.c (w_nbyte, clear_dump_arg): infect the buffer as soon + as appending, because it might have been finalized already at + exit. based on a patch by Tomoyuki Chikanaga + at [ruby-dev:41672]. [Bug #3463] + Wed Jun 23 23:49:21 2010 Tanaka Akira <akr@f...> * ext/socket/raddrinfo.c (str_is_number): renamed from str_isnumber to Index: marshal.c =================================================================== --- marshal.c (revision 28412) +++ marshal.c (revision 28413) @@ -131,14 +131,16 @@ st_insert(compat_allocator_tbl, (st_data_t)allocator, (st_data_t)compat); } +#define MARSHAL_INFECTION (FL_TAINT|FL_UNTRUSTED) +typedef char ruby_check_marshal_viral_flags[MARSHAL_INFECTION == (int)MARSHAL_INFECTION ? 1 : -1]; + struct dump_arg { VALUE str, dest; st_table *symbols; st_table *data; - int taint; - int untrust; st_table *compat_tbl; st_table *encodings; + int infection; }; struct dump_call_arg { @@ -224,9 +226,8 @@ { VALUE buf = arg->str; rb_str_buf_cat(buf, s, n); + RBASIC(buf)->flags |= arg->infection; 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); } @@ -636,8 +637,7 @@ w_symbol(SYM2ID(obj), arg); } else { - if (OBJ_TAINTED(obj)) arg->taint = TRUE; - if (OBJ_UNTRUSTED(obj)) arg->untrust = TRUE; + arg->infection |= FL_TEST(obj, MARSHAL_INFECTION); if (rb_respond_to(obj, s_mdump)) { volatile VALUE v; @@ -856,12 +856,6 @@ st_free_table(arg->encodings); arg->encodings = 0; } - if (arg->taint) { - OBJ_TAINT(arg->str); - } - if (arg->untrust) { - OBJ_UNTRUST(arg->str); - } } /* @@ -922,8 +916,7 @@ arg->dest = 0; arg->symbols = st_init_numtable(); arg->data = st_init_numtable(); - arg->taint = FALSE; - arg->untrust = FALSE; + arg->infection = 0; arg->compat_tbl = st_init_numtable(); arg->encodings = 0; arg->str = rb_str_buf_new(0); @@ -962,9 +955,8 @@ st_table *symbols; st_table *data; VALUE proc; - int taint; - int untrust; st_table *compat_tbl; + int infection; }; static void @@ -1118,8 +1110,7 @@ if (NIL_P(str)) goto too_short; StringValue(str); if (RSTRING_LEN(str) != len) goto too_short; - if (OBJ_TAINTED(str)) arg->taint = TRUE; - if (OBJ_UNTRUSTED(str)) arg->untrust = TRUE; + arg->infection |= FL_TEST(str, MARSHAL_INFECTION); } return str; } @@ -1220,16 +1211,11 @@ else { st_insert(arg->data, num, (st_data_t)v); } - if (arg->taint) { - OBJ_TAINT(v); - if ((VALUE)real_obj != Qundef) - OBJ_TAINT((VALUE)real_obj); + if (arg->infection) { + FL_SET(v, arg->infection); + if ((VALUE)real_obj != Qundef) + FL_SET((VALUE)real_obj, arg->infection); } - if (arg->untrust) { - OBJ_UNTRUST(v); - if ((VALUE)real_obj != Qundef) - OBJ_UNTRUST((VALUE)real_obj); - } return v; } @@ -1765,7 +1751,7 @@ marshal_load(int argc, VALUE *argv) { VALUE port, proc; - int major, minor, taint = FALSE; + int major, minor, infection = 0; VALUE v; volatile VALUE wrapper; struct load_arg *arg; @@ -1773,21 +1759,20 @@ rb_scan_args(argc, argv, "11", &port, &proc); v = rb_check_string_type(port); if (!NIL_P(v)) { - taint = OBJ_TAINTED(port); /* original taintedness */ + infection = FL_TEST(port, MARSHAL_INFECTION); /* original taintedness */ port = v; } else if (rb_respond_to(port, s_getbyte) && rb_respond_to(port, s_read)) { if (rb_respond_to(port, s_binmode)) { rb_funcall2(port, s_binmode, 0, 0); } - taint = TRUE; + infection = FL_TAINT | FL_TEST(port, FL_UNTRUSTED); } else { rb_raise(rb_eTypeError, "instance of IO needed"); } wrapper = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg); - arg->taint = taint; - arg->untrust = OBJ_UNTRUSTED(port); + arg->infection = infection; arg->src = port; arg->offset = 0; arg->symbols = st_init_numtable(); Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 28412) +++ ruby_1_9_2/ChangeLog (revision 28413) @@ -1,3 +1,13 @@ +Thu Jun 24 05:44:27 2010 Nobuyoshi Nakada <nobu@r...> + + * marshal.c (struct dump_arg, struct load_arg): merge taint and + untrust flags into infection as bit flags. + + * marshal.c (w_nbyte, clear_dump_arg): infect the buffer as soon + as appending, because it might have been finalized already at + exit. based on a patch by Tomoyuki Chikanaga + at [ruby-dev:41672]. [Bug #3463] + Wed Jun 23 17:12:27 2010 Nobuyoshi Nakada <nobu@r...> * NEWS (ptr): new method and deprecated methods. [ruby-dev:41681] Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 28412) +++ ruby_1_9_2/version.h (revision 28413) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_RELEASE_DATE "2010-06-23" +#define RUBY_RELEASE_DATE "2010-06-24" #define RUBY_PATCHLEVEL -1 #define RUBY_VERSION_MAJOR 1 @@ -7,7 +7,7 @@ #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_YEAR 2010 #define RUBY_RELEASE_MONTH 6 -#define RUBY_RELEASE_DAY 23 +#define RUBY_RELEASE_DAY 24 #include "ruby/version.h" Index: ruby_1_9_2/marshal.c =================================================================== --- ruby_1_9_2/marshal.c (revision 28412) +++ ruby_1_9_2/marshal.c (revision 28413) @@ -131,14 +131,16 @@ st_insert(compat_allocator_tbl, (st_data_t)allocator, (st_data_t)compat); } +#define MARSHAL_INFECTION (FL_TAINT|FL_UNTRUSTED) +typedef char ruby_check_marshal_viral_flags[MARSHAL_INFECTION == (int)MARSHAL_INFECTION ? 1 : -1]; + struct dump_arg { VALUE str, dest; st_table *symbols; st_table *data; - int taint; - int untrust; st_table *compat_tbl; st_table *encodings; + int infection; }; struct dump_call_arg { @@ -224,9 +226,8 @@ { VALUE buf = arg->str; rb_str_buf_cat(buf, s, n); + RBASIC(buf)->flags |= arg->infection; 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); } @@ -639,8 +640,7 @@ w_symbol(SYM2ID(obj), arg); } else { - if (OBJ_TAINTED(obj)) arg->taint = TRUE; - if (OBJ_UNTRUSTED(obj)) arg->untrust = TRUE; + arg->infection |= FL_TEST(obj, MARSHAL_INFECTION); if (rb_respond_to(obj, s_mdump)) { volatile VALUE v; @@ -859,12 +859,6 @@ st_free_table(arg->encodings); arg->encodings = 0; } - if (arg->taint) { - OBJ_TAINT(arg->str); - } - if (arg->untrust) { - OBJ_UNTRUST(arg->str); - } } /* @@ -925,8 +919,7 @@ arg->dest = 0; arg->symbols = st_init_numtable(); arg->data = st_init_numtable(); - arg->taint = FALSE; - arg->untrust = FALSE; + arg->infection = 0; arg->compat_tbl = st_init_numtable(); arg->encodings = 0; arg->str = rb_str_buf_new(0); @@ -965,9 +958,8 @@ st_table *symbols; st_table *data; VALUE proc; - int taint; - int untrust; st_table *compat_tbl; + int infection; }; static void @@ -1121,8 +1113,7 @@ if (NIL_P(str)) goto too_short; StringValue(str); if (RSTRING_LEN(str) != len) goto too_short; - if (OBJ_TAINTED(str)) arg->taint = TRUE; - if (OBJ_UNTRUSTED(str)) arg->untrust = TRUE; + arg->infection |= FL_TEST(str, MARSHAL_INFECTION); } return str; } @@ -1223,16 +1214,11 @@ else { st_insert(arg->data, num, (st_data_t)v); } - if (arg->taint) { - OBJ_TAINT(v); - if ((VALUE)real_obj != Qundef) - OBJ_TAINT((VALUE)real_obj); + if (arg->infection) { + FL_SET(v, arg->infection); + if ((VALUE)real_obj != Qundef) + FL_SET((VALUE)real_obj, arg->infection); } - if (arg->untrust) { - OBJ_UNTRUST(v); - if ((VALUE)real_obj != Qundef) - OBJ_UNTRUST((VALUE)real_obj); - } return v; } @@ -1768,7 +1754,7 @@ marshal_load(int argc, VALUE *argv) { VALUE port, proc; - int major, minor, taint = FALSE; + int major, minor, infection = 0; VALUE v; volatile VALUE wrapper; struct load_arg *arg; @@ -1776,21 +1762,20 @@ rb_scan_args(argc, argv, "11", &port, &proc); v = rb_check_string_type(port); if (!NIL_P(v)) { - taint = OBJ_TAINTED(port); /* original taintedness */ + infection = FL_TEST(port, MARSHAL_INFECTION); /* original taintedness */ port = v; } else if (rb_respond_to(port, s_getbyte) && rb_respond_to(port, s_read)) { if (rb_respond_to(port, s_binmode)) { rb_funcall2(port, s_binmode, 0, 0); } - taint = TRUE; + infection = FL_TAINT | FL_TEST(port, FL_UNTRUSTED); } else { rb_raise(rb_eTypeError, "instance of IO needed"); } wrapper = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg); - arg->taint = taint; - arg->untrust = OBJ_UNTRUSTED(port); + arg->infection = infection; arg->src = port; arg->offset = 0; arg->symbols = st_init_numtable(); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/