Skip to content

Commit 377d5c9

Browse files
committed
Untrusted status is a synonym of tainted.
1 parent f95ebcf commit 377d5c9

File tree

12 files changed

+45
-168
lines changed

12 files changed

+45
-168
lines changed

core/array.rb

-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ def combination(num)
570570
def compact
571571
out = dup
572572
out.untaint if out.tainted?
573-
out.trust if out.untrusted?
574573

575574
Array.new(out.compact! || out)
576575
end

core/kernel.rb

+3-14
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,9 @@ def untaint
6969
raise PrimitiveFailure, "Kernel#untaint primitive failed"
7070
end
7171

72-
def trust
73-
Rubinius.primitive :object_trust
74-
raise PrimitiveFailure, "Kernel#trust primitive failed"
75-
end
76-
77-
def untrust
78-
Rubinius.primitive :object_untrust
79-
raise PrimitiveFailure, "Kernel#untrust primitive failed"
80-
end
81-
82-
def untrusted?
83-
Rubinius.primitive :object_untrusted_p
84-
raise PrimitiveFailure, "Kernel#untrusted? primitive failed"
85-
end
72+
alias_method :untrust, :taint
73+
alias_method :trust, :untaint
74+
alias_method :untrusted?, :tainted?
8675

8776
# NOTE: The bootstrap method used to add method definitions to the class
8877
# method_table still returns a CompiledCode instance, so this chaining

core/marshal.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ def construct(ivar_index = nil, call_proc = true)
572572

573573
call obj if @proc and call_proc
574574

575-
@stream.tainted? && !obj.frozen? ? obj.taint : obj
575+
Rubinius::Type.infect obj, @stream unless obj.frozen?
576+
577+
obj
576578
end
577579

578580
def construct_class

core/string.rb

+38-59
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ def %(args)
224224
*args = args
225225
ret = Rubinius::Sprinter.get(self).call(*args)
226226

227-
ret.taint if tainted?
228-
return ret
227+
Rubinius::Type.infect ret, self
229228
end
230229

231230
def *(num)
@@ -413,8 +412,9 @@ def crypt(other_str)
413412
end
414413

415414
hash = __crypt__(other_str)
416-
hash.taint if tainted? || other_str.tainted?
417-
hash
415+
416+
Rubinius::Type.infect hash, self
417+
Rubinius::Type.infect hash, other_str
418418
end
419419

420420
def delete(*strings)
@@ -1338,32 +1338,28 @@ def sub(pattern, replacement=undefined)
13381338
raise ArgumentError, "invalid byte sequence in #{encoding}"
13391339
end
13401340

1341+
ret = byteslice(0, 0) # Empty string and string subclass
1342+
13411343
if undefined.equal? replacement
13421344
unless block_given?
13431345
raise ArgumentError, "method '#{__method__}': given 1, expected 2"
13441346
end
13451347
use_yield = true
1346-
tainted = false
13471348
else
1348-
tainted = replacement.tainted?
1349-
untrusted = replacement.untrusted?
1350-
13511349
unless replacement.kind_of?(String)
13521350
hash = Rubinius::Type.check_convert_type(replacement, Hash, :to_hash)
13531351
replacement = StringValue(replacement) unless hash
1354-
tainted ||= replacement.tainted?
1355-
untrusted ||= replacement.untrusted?
13561352
end
13571353
use_yield = false
1354+
1355+
Rubinius::Type.infect ret, replacement
13581356
end
13591357

13601358
pattern = Rubinius::Type.coerce_to_regexp(pattern, true) unless pattern.kind_of? Regexp
13611359
match = pattern.match_from(self, 0)
13621360

13631361
Regexp.last_match = match
13641362

1365-
ret = byteslice(0, 0) # Empty string and string subclass
1366-
13671363
if match
13681364
ret.append match.pre_match
13691365

@@ -1375,25 +1371,21 @@ def sub(pattern, replacement=undefined)
13751371
else
13761372
val = hash[match.to_s]
13771373
end
1378-
untrusted = true if val.untrusted?
13791374
val = val.to_s unless val.kind_of?(String)
13801375

1381-
tainted ||= val.tainted?
1376+
Rubinius::Type.infect ret, val
13821377

13831378
ret.append val
13841379
else
13851380
replacement.to_sub_replacement(ret, match)
13861381
end
13871382

1383+
Rubinius::Type.infect ret, val
13881384
ret.append(match.post_match)
1389-
tainted ||= val.tainted?
13901385
else
13911386
ret = dup
13921387
end
13931388

1394-
ret.taint if tainted
1395-
ret.untrust if untrusted
1396-
13971389
ret
13981390
end
13991391

@@ -1405,34 +1397,31 @@ def sub!(pattern, replacement=undefined)
14051397
raise ArgumentError, "invalid byte sequence in #{encoding}"
14061398
end
14071399

1400+
ret = byteslice(0, 0) # Empty string and string subclass
1401+
14081402
if undefined.equal? replacement
14091403
unless block_given?
14101404
raise ArgumentError, "method '#{__method__}': given 1, expected 2"
14111405
end
14121406
Rubinius.check_frozen
14131407
use_yield = true
1414-
tainted = false
14151408
else
14161409
Rubinius.check_frozen
1417-
tainted = replacement.tainted?
1418-
untrusted = replacement.untrusted?
14191410

14201411
unless replacement.kind_of?(String)
14211412
hash = Rubinius::Type.check_convert_type(replacement, Hash, :to_hash)
14221413
replacement = StringValue(replacement) unless hash
1423-
tainted ||= replacement.tainted?
1424-
untrusted ||= replacement.untrusted?
14251414
end
14261415
use_yield = false
1416+
1417+
Rubinius::Type.infect ret, replacement
14271418
end
14281419

14291420
pattern = Rubinius::Type.coerce_to_regexp(pattern, true) unless pattern.kind_of? Regexp
14301421
match = pattern.match_from(self, 0)
14311422

14321423
Regexp.last_match = match
14331424

1434-
ret = byteslice(0, 0) # Empty string and string subclass
1435-
14361425
if match
14371426
ret.append match.pre_match
14381427

@@ -1444,25 +1433,22 @@ def sub!(pattern, replacement=undefined)
14441433
else
14451434
val = hash[match.to_s]
14461435
end
1447-
untrusted = true if val.untrusted?
14481436
val = val.to_s unless val.kind_of?(String)
14491437

1450-
tainted ||= val.tainted?
1438+
Rubinius::Type.infect ret, val
14511439

14521440
ret.append val
14531441
else
14541442
replacement.to_sub_replacement(ret, match)
14551443
end
14561444

1445+
Rubinius::Type.infect ret, val
1446+
14571447
ret.append(match.post_match)
1458-
tainted ||= val.tainted?
14591448
else
14601449
return nil
14611450
end
14621451

1463-
ret.taint if tainted
1464-
ret.untrust if untrusted
1465-
14661452
replace(ret)
14671453
self
14681454
end
@@ -1852,23 +1838,21 @@ def gsub(pattern, replacement=undefined)
18521838
raise ArgumentError, "invalid byte sequence in #{encoding}"
18531839
end
18541840

1841+
ret = byteslice(0, 0) # Empty string and string subclass
1842+
18551843
if undefined.equal? replacement
18561844
unless block_given?
18571845
return to_enum(:gsub, pattern, replacement)
18581846
end
18591847
use_yield = true
1860-
tainted = false
18611848
else
1862-
tainted = replacement.tainted?
1863-
untrusted = replacement.untrusted?
1864-
18651849
unless replacement.kind_of?(String)
18661850
hash = Rubinius::Type.check_convert_type(replacement, Hash, :to_hash)
18671851
replacement = StringValue(replacement) unless hash
1868-
tainted ||= replacement.tainted?
1869-
untrusted ||= replacement.untrusted?
18701852
end
18711853
use_yield = false
1854+
1855+
Rubinius::Type.infect ret, replacement
18721856
end
18731857

18741858
pattern = Rubinius::Type.coerce_to_regexp(pattern, true) unless pattern.kind_of? Regexp
@@ -1886,7 +1870,6 @@ def gsub(pattern, replacement=undefined)
18861870

18871871
last_match = nil
18881872

1889-
ret = byteslice(0, 0) # Empty string and string subclass
18901873
offset = match.full.at(0) if match
18911874

18921875
while match
@@ -1902,10 +1885,9 @@ def gsub(pattern, replacement=undefined)
19021885
else
19031886
val = hash[match.to_s]
19041887
end
1905-
untrusted = true if val.untrusted?
19061888
val = val.to_s unless val.kind_of?(String)
19071889

1908-
tainted ||= val.tainted?
1890+
Rubinius::Type.infect ret, val
19091891

19101892
ret.append val
19111893

@@ -1916,7 +1898,7 @@ def gsub(pattern, replacement=undefined)
19161898
replacement.to_sub_replacement(ret, match)
19171899
end
19181900

1919-
tainted ||= val.tainted?
1901+
Rubinius::Type.infect ret, val
19201902

19211903
last_end = match.full.at(1)
19221904

@@ -1945,9 +1927,6 @@ def gsub(pattern, replacement=undefined)
19451927
ret.append str
19461928
end
19471929

1948-
ret.taint if tainted
1949-
ret.untrust if untrusted
1950-
19511930
ret
19521931
end
19531932

@@ -1959,25 +1938,24 @@ def gsub!(pattern, replacement=undefined)
19591938
raise ArgumentError, "invalid byte sequence in #{encoding}"
19601939
end
19611940

1941+
ret = byteslice(0, 0) # Empty string and string subclass
1942+
19621943
if undefined.equal? replacement
19631944
unless block_given?
19641945
return to_enum(:gsub, pattern, replacement)
19651946
end
19661947
Rubinius.check_frozen
19671948
use_yield = true
1968-
tainted = false
19691949
else
19701950
Rubinius.check_frozen
1971-
tainted = replacement.tainted?
1972-
untrusted = replacement.untrusted?
19731951

19741952
unless replacement.kind_of?(String)
19751953
hash = Rubinius::Type.check_convert_type(replacement, Hash, :to_hash)
19761954
replacement = StringValue(replacement) unless hash
1977-
tainted ||= replacement.tainted?
1978-
untrusted ||= replacement.untrusted?
19791955
end
19801956
use_yield = false
1957+
1958+
Rubinius::Type.infect ret, replacement
19811959
end
19821960

19831961
pattern = Rubinius::Type.coerce_to_regexp(pattern, true) unless pattern.kind_of? Regexp
@@ -1996,7 +1974,6 @@ def gsub!(pattern, replacement=undefined)
19961974

19971975
last_match = nil
19981976

1999-
ret = byteslice(0, 0) # Empty string and string subclass
20001977
offset = match.full.at(0)
20011978

20021979
while match
@@ -2012,10 +1989,9 @@ def gsub!(pattern, replacement=undefined)
20121989
else
20131990
val = hash[match.to_s]
20141991
end
2015-
untrusted = true if val.untrusted?
20161992
val = val.to_s unless val.kind_of?(String)
20171993

2018-
tainted ||= val.tainted?
1994+
Rubinius::Type.infect ret, val
20191995

20201996
ret.append val
20211997

@@ -2026,7 +2002,7 @@ def gsub!(pattern, replacement=undefined)
20262002
replacement.to_sub_replacement(ret, match)
20272003
end
20282004

2029-
tainted ||= val.tainted?
2005+
Rubinius::Type.infect ret, val
20302006

20312007
last_end = match.full.at(1)
20322008

@@ -2055,9 +2031,6 @@ def gsub!(pattern, replacement=undefined)
20552031
ret.append str
20562032
end
20572033

2058-
ret.taint if tainted
2059-
ret.untrust if untrusted
2060-
20612034
replace(ret)
20622035
self
20632036
end
@@ -2314,7 +2287,9 @@ def center(width, padding=" ")
23142287
m.copy_from self, 0, bs, left
23152288
end
23162289

2317-
str.taint if tainted? or padding.tainted?
2290+
Rubinius::Type.infect str, self
2291+
Rubinius::Type.infect str, padding
2292+
23182293
str.force_encoding enc
23192294
end
23202295

@@ -2363,7 +2338,9 @@ def ljust(width, padding=" ")
23632338
m.copy_from self, 0, bs, 0
23642339
end
23652340

2366-
str.taint if tainted? or padding.tainted?
2341+
Rubinius::Type.infect str, self
2342+
Rubinius::Type.infect str, padding
2343+
23672344
str.force_encoding enc
23682345
end
23692346

@@ -2398,7 +2375,9 @@ def rjust(width, padding=" ")
23982375

23992376
m.copy_from self, 0, bs, bytes
24002377

2401-
str.taint if tainted? or padding.tainted?
2378+
Rubinius::Type.infect str, self
2379+
Rubinius::Type.infect str, padding
2380+
24022381
str.force_encoding enc
24032382
end
24042383

0 commit comments

Comments
 (0)