Skip to content

Commit

Permalink
Untrusted status is a synonym of tainted.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Apr 10, 2016
1 parent f95ebcf commit 377d5c9
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 168 deletions.
1 change: 0 additions & 1 deletion core/array.rb
Expand Up @@ -570,7 +570,6 @@ def combination(num)
def compact
out = dup
out.untaint if out.tainted?
out.trust if out.untrusted?

Array.new(out.compact! || out)
end
Expand Down
17 changes: 3 additions & 14 deletions core/kernel.rb
Expand Up @@ -69,20 +69,9 @@ def untaint
raise PrimitiveFailure, "Kernel#untaint primitive failed"
end

def trust
Rubinius.primitive :object_trust
raise PrimitiveFailure, "Kernel#trust primitive failed"
end

def untrust
Rubinius.primitive :object_untrust
raise PrimitiveFailure, "Kernel#untrust primitive failed"
end

def untrusted?
Rubinius.primitive :object_untrusted_p
raise PrimitiveFailure, "Kernel#untrusted? primitive failed"
end
alias_method :untrust, :taint
alias_method :trust, :untaint
alias_method :untrusted?, :tainted?

# NOTE: The bootstrap method used to add method definitions to the class
# method_table still returns a CompiledCode instance, so this chaining
Expand Down
4 changes: 3 additions & 1 deletion core/marshal.rb
Expand Up @@ -572,7 +572,9 @@ def construct(ivar_index = nil, call_proc = true)

call obj if @proc and call_proc

@stream.tainted? && !obj.frozen? ? obj.taint : obj
Rubinius::Type.infect obj, @stream unless obj.frozen?

obj
end

def construct_class
Expand Down
97 changes: 38 additions & 59 deletions core/string.rb
Expand Up @@ -224,8 +224,7 @@ def %(args)
*args = args
ret = Rubinius::Sprinter.get(self).call(*args)

ret.taint if tainted?
return ret
Rubinius::Type.infect ret, self
end

def *(num)
Expand Down Expand Up @@ -413,8 +412,9 @@ def crypt(other_str)
end

hash = __crypt__(other_str)
hash.taint if tainted? || other_str.tainted?
hash

Rubinius::Type.infect hash, self
Rubinius::Type.infect hash, other_str
end

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

ret = byteslice(0, 0) # Empty string and string subclass

if undefined.equal? replacement
unless block_given?
raise ArgumentError, "method '#{__method__}': given 1, expected 2"
end
use_yield = true
tainted = false
else
tainted = replacement.tainted?
untrusted = replacement.untrusted?

unless replacement.kind_of?(String)
hash = Rubinius::Type.check_convert_type(replacement, Hash, :to_hash)
replacement = StringValue(replacement) unless hash
tainted ||= replacement.tainted?
untrusted ||= replacement.untrusted?
end
use_yield = false

Rubinius::Type.infect ret, replacement
end

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

Regexp.last_match = match

ret = byteslice(0, 0) # Empty string and string subclass

if match
ret.append match.pre_match

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

tainted ||= val.tainted?
Rubinius::Type.infect ret, val

ret.append val
else
replacement.to_sub_replacement(ret, match)
end

Rubinius::Type.infect ret, val
ret.append(match.post_match)
tainted ||= val.tainted?
else
ret = dup
end

ret.taint if tainted
ret.untrust if untrusted

ret
end

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

ret = byteslice(0, 0) # Empty string and string subclass

if undefined.equal? replacement
unless block_given?
raise ArgumentError, "method '#{__method__}': given 1, expected 2"
end
Rubinius.check_frozen
use_yield = true
tainted = false
else
Rubinius.check_frozen
tainted = replacement.tainted?
untrusted = replacement.untrusted?

unless replacement.kind_of?(String)
hash = Rubinius::Type.check_convert_type(replacement, Hash, :to_hash)
replacement = StringValue(replacement) unless hash
tainted ||= replacement.tainted?
untrusted ||= replacement.untrusted?
end
use_yield = false

Rubinius::Type.infect ret, replacement
end

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

Regexp.last_match = match

ret = byteslice(0, 0) # Empty string and string subclass

if match
ret.append match.pre_match

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

tainted ||= val.tainted?
Rubinius::Type.infect ret, val

ret.append val
else
replacement.to_sub_replacement(ret, match)
end

Rubinius::Type.infect ret, val

ret.append(match.post_match)
tainted ||= val.tainted?
else
return nil
end

ret.taint if tainted
ret.untrust if untrusted

replace(ret)
self
end
Expand Down Expand Up @@ -1852,23 +1838,21 @@ def gsub(pattern, replacement=undefined)
raise ArgumentError, "invalid byte sequence in #{encoding}"
end

ret = byteslice(0, 0) # Empty string and string subclass

if undefined.equal? replacement
unless block_given?
return to_enum(:gsub, pattern, replacement)
end
use_yield = true
tainted = false
else
tainted = replacement.tainted?
untrusted = replacement.untrusted?

unless replacement.kind_of?(String)
hash = Rubinius::Type.check_convert_type(replacement, Hash, :to_hash)
replacement = StringValue(replacement) unless hash
tainted ||= replacement.tainted?
untrusted ||= replacement.untrusted?
end
use_yield = false

Rubinius::Type.infect ret, replacement
end

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

last_match = nil

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

while match
Expand All @@ -1902,10 +1885,9 @@ def gsub(pattern, replacement=undefined)
else
val = hash[match.to_s]
end
untrusted = true if val.untrusted?
val = val.to_s unless val.kind_of?(String)

tainted ||= val.tainted?
Rubinius::Type.infect ret, val

ret.append val

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

tainted ||= val.tainted?
Rubinius::Type.infect ret, val

last_end = match.full.at(1)

Expand Down Expand Up @@ -1945,9 +1927,6 @@ def gsub(pattern, replacement=undefined)
ret.append str
end

ret.taint if tainted
ret.untrust if untrusted

ret
end

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

ret = byteslice(0, 0) # Empty string and string subclass

if undefined.equal? replacement
unless block_given?
return to_enum(:gsub, pattern, replacement)
end
Rubinius.check_frozen
use_yield = true
tainted = false
else
Rubinius.check_frozen
tainted = replacement.tainted?
untrusted = replacement.untrusted?

unless replacement.kind_of?(String)
hash = Rubinius::Type.check_convert_type(replacement, Hash, :to_hash)
replacement = StringValue(replacement) unless hash
tainted ||= replacement.tainted?
untrusted ||= replacement.untrusted?
end
use_yield = false

Rubinius::Type.infect ret, replacement
end

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

last_match = nil

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

while match
Expand All @@ -2012,10 +1989,9 @@ def gsub!(pattern, replacement=undefined)
else
val = hash[match.to_s]
end
untrusted = true if val.untrusted?
val = val.to_s unless val.kind_of?(String)

tainted ||= val.tainted?
Rubinius::Type.infect ret, val

ret.append val

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

tainted ||= val.tainted?
Rubinius::Type.infect ret, val

last_end = match.full.at(1)

Expand Down Expand Up @@ -2055,9 +2031,6 @@ def gsub!(pattern, replacement=undefined)
ret.append str
end

ret.taint if tainted
ret.untrust if untrusted

replace(ret)
self
end
Expand Down Expand Up @@ -2314,7 +2287,9 @@ def center(width, padding=" ")
m.copy_from self, 0, bs, left
end

str.taint if tainted? or padding.tainted?
Rubinius::Type.infect str, self
Rubinius::Type.infect str, padding

str.force_encoding enc
end

Expand Down Expand Up @@ -2363,7 +2338,9 @@ def ljust(width, padding=" ")
m.copy_from self, 0, bs, 0
end

str.taint if tainted? or padding.tainted?
Rubinius::Type.infect str, self
Rubinius::Type.infect str, padding

str.force_encoding enc
end

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

m.copy_from self, 0, bs, bytes

str.taint if tainted? or padding.tainted?
Rubinius::Type.infect str, self
Rubinius::Type.infect str, padding

str.force_encoding enc
end

Expand Down

0 comments on commit 377d5c9

Please sign in to comment.