Skip to content

Commit ffd0820

Browse files
committed
Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
1 parent c5c0546 commit ffd0820

File tree

201 files changed

+2319
-2901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+2319
-2901
lines changed

array.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,6 @@ ary_join_0(VALUE ary, VALUE sep, long max, VALUE result)
22852285
if (i > 0 && !NIL_P(sep))
22862286
rb_str_buf_append(result, sep);
22872287
rb_str_buf_append(result, val);
2288-
if (OBJ_TAINTED(val)) OBJ_TAINT(result);
22892288
}
22902289
}
22912290

@@ -2346,11 +2345,9 @@ VALUE
23462345
rb_ary_join(VALUE ary, VALUE sep)
23472346
{
23482347
long len = 1, i;
2349-
int taint = FALSE;
23502348
VALUE val, tmp, result;
23512349

23522350
if (RARRAY_LEN(ary) == 0) return rb_usascii_str_new(0, 0);
2353-
if (OBJ_TAINTED(ary)) taint = TRUE;
23542351

23552352
if (!NIL_P(sep)) {
23562353
StringValue(sep);
@@ -2364,7 +2361,6 @@ rb_ary_join(VALUE ary, VALUE sep)
23642361
int first;
23652362
result = rb_str_buf_new(len + (RARRAY_LEN(ary)-i)*10);
23662363
rb_enc_associate(result, rb_usascii_encoding());
2367-
if (taint) OBJ_TAINT(result);
23682364
ary_join_0(ary, sep, i, result);
23692365
first = i == 0;
23702366
ary_join_1(ary, ary, sep, i, result, &first);
@@ -2377,7 +2373,6 @@ rb_ary_join(VALUE ary, VALUE sep)
23772373
result = rb_str_new(0, len);
23782374
rb_str_set_len(result, 0);
23792375

2380-
if (taint) OBJ_TAINT(result);
23812376
ary_join_0(ary, sep, RARRAY_LEN(ary), result);
23822377

23832378
return result;
@@ -2419,21 +2414,18 @@ rb_ary_join_m(int argc, VALUE *argv, VALUE ary)
24192414
static VALUE
24202415
inspect_ary(VALUE ary, VALUE dummy, int recur)
24212416
{
2422-
int tainted = OBJ_TAINTED(ary);
24232417
long i;
24242418
VALUE s, str;
24252419

24262420
if (recur) return rb_usascii_str_new_cstr("[...]");
24272421
str = rb_str_buf_new2("[");
24282422
for (i=0; i<RARRAY_LEN(ary); i++) {
24292423
s = rb_inspect(RARRAY_AREF(ary, i));
2430-
if (OBJ_TAINTED(s)) tainted = TRUE;
24312424
if (i > 0) rb_str_buf_cat2(str, ", ");
24322425
else rb_enc_copy(str, s);
24332426
rb_str_buf_append(str, s);
24342427
}
24352428
rb_str_buf_cat2(str, "]");
2436-
if (tainted) OBJ_TAINT(str);
24372429
return str;
24382430
}
24392431

@@ -4135,8 +4127,6 @@ rb_ary_times(VALUE ary, VALUE times)
41354127
}
41364128
}
41374129
out:
4138-
OBJ_INFECT(ary2, ary);
4139-
41404130
return ary2;
41414131
}
41424132

@@ -5315,7 +5305,6 @@ rb_ary_flatten(int argc, VALUE *argv, VALUE ary)
53155305
if (result == ary) {
53165306
result = ary_make_shared_copy(ary);
53175307
}
5318-
OBJ_INFECT(result, ary);
53195308

53205309
return result;
53215310
}

bin/erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ EOU
128128
exit 2 unless src
129129
trim = trim_mode_opt(trim_mode, disable_percent)
130130
if safe_level.nil?
131-
erb = factory.new(src.untaint, trim_mode: trim)
131+
erb = factory.new(src, trim_mode: trim)
132132
else
133133
# [deprecated] This will be removed at Ruby 2.7.
134-
erb = factory.new(src.untaint, safe_level, trim_mode: trim)
134+
erb = factory.new(src, safe_level, trim_mode: trim)
135135
end
136136
erb.filename = filename
137137
if output
@@ -143,7 +143,7 @@ EOU
143143
puts erb.src
144144
end
145145
else
146-
bind = TOPLEVEL_BINDING.taint
146+
bind = TOPLEVEL_BINDING
147147
if variables
148148
enc = erb.encoding
149149
for var, val in variables do

class.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ rb_class_boot(VALUE super)
205205
RCLASS_SET_SUPER(klass, super);
206206
RCLASS_M_TBL_INIT(klass);
207207

208-
OBJ_INFECT(klass, super);
209208
return (VALUE)klass;
210209
}
211210

@@ -511,8 +510,6 @@ make_metaclass(VALUE klass)
511510
while (RB_TYPE_P(super, T_ICLASS)) super = RCLASS_SUPER(super);
512511
RCLASS_SET_SUPER(metaclass, super ? ENSURE_EIGENCLASS(super) : rb_cClass);
513512

514-
OBJ_INFECT(metaclass, RCLASS_SUPER(metaclass));
515-
516513
return metaclass;
517514
}
518515

@@ -851,8 +848,6 @@ rb_include_class_new(VALUE module, VALUE super)
851848
else {
852849
RBASIC_SET_CLASS(klass, module);
853850
}
854-
OBJ_INFECT(klass, module);
855-
OBJ_INFECT(klass, super);
856851

857852
return (VALUE)klass;
858853
}
@@ -867,7 +862,6 @@ ensure_includable(VALUE klass, VALUE module)
867862
if (!NIL_P(rb_refinement_module_get_refined_class(module))) {
868863
rb_raise(rb_eArgError, "refinement module is not allowed");
869864
}
870-
OBJ_INFECT(klass, module);
871865
}
872866

873867
void
@@ -1660,12 +1654,6 @@ singleton_class_of(VALUE obj)
16601654
RCLASS_SERIAL(klass) = serial;
16611655
}
16621656

1663-
if (OBJ_TAINTED(obj)) {
1664-
OBJ_TAINT(klass);
1665-
}
1666-
else {
1667-
FL_UNSET(klass, FL_TAINT);
1668-
}
16691657
RB_FL_SET_RAW(klass, RB_OBJ_FROZEN_RAW(obj));
16701658

16711659
return klass;

dir.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,8 @@ rb_dir_getwd_ospath(void)
11291129
DATA_PTR(path_guard) = path;
11301130
#ifdef __APPLE__
11311131
cwd = rb_str_normalize_ospath(path, strlen(path));
1132-
OBJ_TAINT(cwd);
11331132
#else
1134-
cwd = rb_tainted_str_new2(path);
1133+
cwd = rb_str_new2(path);
11351134
#endif
11361135
DATA_PTR(path_guard) = 0;
11371136

@@ -2564,7 +2563,6 @@ push_pattern(const char *path, VALUE ary, void *enc)
25642563
#if defined _WIN32 || defined __APPLE__
25652564
VALUE name = rb_utf8_str_new_cstr(path);
25662565
rb_encoding *eenc = rb_default_internal_encoding();
2567-
OBJ_TAINT(name);
25682566
name = rb_str_conv_enc(name, NULL, eenc ? eenc : enc);
25692567
#else
25702568
VALUE name = rb_external_str_new_with_enc(path, strlen(path), enc);

encoding.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ load_encoding(const char *name)
649649
else if (ISUPPER(*s)) *s = (char)TOLOWER(*s);
650650
++s;
651651
}
652-
FL_UNSET(enclib, FL_TAINT);
653652
enclib = rb_fstring(enclib);
654653
ruby_verbose = Qfalse;
655654
ruby_debug = Qfalse;

enum.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@ enum_to_a(int argc, VALUE *argv, VALUE obj)
647647
VALUE ary = rb_ary_new();
648648

649649
rb_block_call(obj, id_each, argc, argv, collect_all, ary);
650-
OBJ_INFECT(ary, obj);
651650

652651
return ary;
653652
}
@@ -657,7 +656,6 @@ enum_hashify(VALUE obj, int argc, const VALUE *argv, rb_block_call_func *iter)
657656
{
658657
VALUE hash = rb_hash_new();
659658
rb_block_call(obj, id_each, argc, argv, iter, hash);
660-
OBJ_INFECT(hash, obj);
661659
return hash;
662660
}
663661

@@ -1245,7 +1243,6 @@ enum_sort_by(VALUE obj)
12451243
buf = rb_ary_tmp_new(SORT_BY_BUFSIZE*2);
12461244
rb_ary_store(buf, SORT_BY_BUFSIZE*2-1, Qnil);
12471245
memo = MEMO_NEW(0, 0, 0);
1248-
OBJ_INFECT(memo, obj);
12491246
data = (struct sort_by_data *)&memo->v1;
12501247
RB_OBJ_WRITE(memo, &data->ary, ary);
12511248
RB_OBJ_WRITE(memo, &data->buf, buf);
@@ -1270,7 +1267,6 @@ enum_sort_by(VALUE obj)
12701267
}
12711268
rb_ary_resize(ary, RARRAY_LEN(ary)/2);
12721269
RBASIC_SET_CLASS_RAW(ary, rb_cArray);
1273-
OBJ_INFECT(ary, memo);
12741270

12751271
return ary;
12761272
}

enumerator.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,6 @@ inspect_enumerator(VALUE obj, VALUE dummy, int recur)
10771077

10781078
if (recur) {
10791079
str = rb_sprintf("#<%"PRIsVALUE": ...>", rb_class_path(cname));
1080-
OBJ_TAINT(str);
10811080
return str;
10821081
}
10831082

@@ -1172,7 +1171,6 @@ append_method(VALUE obj, VALUE str, ID default_method, VALUE default_args)
11721171

11731172
rb_str_append(str, rb_inspect(arg));
11741173
rb_str_buf_cat2(str, ", ");
1175-
OBJ_INFECT(str, arg);
11761174
}
11771175
if (!NIL_P(kwds)) {
11781176
rb_hash_foreach(kwds, kwd_append, str);
@@ -3609,7 +3607,6 @@ arith_seq_inspect(VALUE self)
36093607

36103608
rb_str_append(str, rb_inspect(arg));
36113609
rb_str_buf_cat2(str, ", ");
3612-
OBJ_INFECT(str, arg);
36133610
}
36143611
if (!NIL_P(kwds)) {
36153612
rb_hash_foreach(kwds, kwd_append, str);

error.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,6 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
20182018

20192019
if (!NIL_P(func)) rb_str_catf(errmsg, " @ %"PRIsVALUE, func);
20202020
rb_str_catf(errmsg, " - %"PRIsVALUE, str);
2021-
OBJ_INFECT(errmsg, mesg);
20222021
}
20232022
mesg = errmsg;
20242023

@@ -2319,19 +2318,7 @@ syserr_eqq(VALUE self, VALUE exc)
23192318
/*
23202319
* Document-class: SecurityError
23212320
*
2322-
* Raised when attempting a potential unsafe operation, typically when
2323-
* the $SAFE level is raised above 0.
2324-
*
2325-
* foo = "bar"
2326-
* proc = Proc.new do
2327-
* $SAFE = 3
2328-
* foo.untaint
2329-
* end
2330-
* proc.call
2331-
*
2332-
* <em>raises the exception:</em>
2333-
*
2334-
* SecurityError: Insecure: Insecure operation `untaint' at level 3
2321+
* No longer used by internal code.
23352322
*/
23362323

23372324
/*
@@ -2971,12 +2958,14 @@ rb_check_frozen(VALUE obj)
29712958
void
29722959
rb_error_untrusted(VALUE obj)
29732960
{
2961+
rb_warning("rb_error_untrusted is deprecated and will be removed in Ruby 3.2.");
29742962
}
29752963

29762964
#undef rb_check_trusted
29772965
void
29782966
rb_check_trusted(VALUE obj)
29792967
{
2968+
rb_warning("rb_check_trusted is deprecated and will be removed in Ruby 3.2.");
29802969
}
29812970

29822971
void

ext/cgi/escape/escape.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ static inline void
3030
preserve_original_state(VALUE orig, VALUE dest)
3131
{
3232
rb_enc_associate(dest, rb_enc_get(orig));
33-
34-
RB_OBJ_INFECT_RAW(dest, orig);
3533
}
3634

3735
static VALUE

ext/etc/etc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ etc_getpwnam(VALUE obj, VALUE nam)
219219
struct passwd *pwd;
220220
const char *p = StringValueCStr(nam);
221221

222+
rb_check_safe_obj(nam);
222223
pwd = getpwnam(p);
223224
if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, nam);
224225
return setup_passwd(pwd);
@@ -462,6 +463,7 @@ etc_getgrnam(VALUE obj, VALUE nam)
462463
struct group *grp;
463464
const char *p = StringValueCStr(nam);
464465

466+
rb_check_safe_obj(nam);
465467
grp = getgrnam(p);
466468
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, nam);
467469
return setup_group(grp);

0 commit comments

Comments
 (0)