Skip to content

Commit

Permalink
Showing 12 changed files with 45 additions and 168 deletions.
1 change: 0 additions & 1 deletion core/array.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 3 additions & 14 deletions core/kernel.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion core/marshal.rb
Original file line number Diff line number Diff line change
@@ -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
97 changes: 38 additions & 59 deletions core/string.rb
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
@@ -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

@@ -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

@@ -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

@@ -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
@@ -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
@@ -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
@@ -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

@@ -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)

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

ret.taint if tainted
ret.untrust if untrusted

ret
end

@@ -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
@@ -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
@@ -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

@@ -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)

@@ -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
@@ -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

@@ -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

@@ -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

24 changes: 0 additions & 24 deletions machine/builtin/object.cpp
Original file line number Diff line number Diff line change
@@ -438,10 +438,6 @@ namespace rubinius {
if(is_tainted_p()) {
other->taint(state);
}

if(is_untrusted_p()) {
other->untrust(state);
}
}

bool Object::kind_of_p(STATE, Object* module) {
@@ -829,26 +825,6 @@ namespace rubinius {
return RBOOL(is_tainted_p());
}

Object* Object::trust(STATE) {
if(is_untrusted_p()) {
check_frozen(state);
set_untrusted(0);
}
return this;
}

Object* Object::untrust(STATE) {
if(!is_untrusted_p()) {
check_frozen(state);
if(reference_p()) set_untrusted();
}
return this;
}

Object* Object::untrusted_p(STATE) {
return RBOOL(is_untrusted_p());
}

TypeInfo* Object::type_info(STATE) const {
return state->memory()->type_info[get_type()];
}
18 changes: 0 additions & 18 deletions machine/builtin/object.hpp
Original file line number Diff line number Diff line change
@@ -302,24 +302,6 @@ namespace rubinius {
// Rubinius.primitive :object_untaint
Object* untaint(STATE);

/**
* Returns true if this object's untrusted flag is set.
*/
// Rubinius.primitive+ :object_untrusted_p
Object* untrusted_p(STATE);

/**
* Sets the untrusted flag on this object.
*/
// Rubinius.primitive :object_untrust
Object* untrust(STATE);

/**
* Clears the untrusted flag on this object.
*/
// Rubinius.primitive :object_trust
Object* trust(STATE);

/**
* Returns an #inspect-like representation of an Object for
* use in C++ code.
9 changes: 0 additions & 9 deletions machine/builtin/pack.cpp
Original file line number Diff line number Diff line change
@@ -643,7 +643,6 @@ namespace rubinius {
native_int stop = 0;
bool rest UNUSED = false;
bool tainted UNUSED = false;
bool untrusted UNUSED = false;
bool ascii_encoding = false;
bool utf8_encoding = false;
bool string_encoding = false;
@@ -656,7 +655,6 @@ namespace rubinius {

if(directives->byte_size() == 0) ascii_encoding = true;
if(CBOOL(directives->tainted_p(state))) tainted = true;
if(CBOOL(directives->untrusted_p(state))) untrusted = true;

static const char _actions[] = {
0, 1, 0, 1, 1, 1, 2, 1,
@@ -3255,7 +3253,6 @@ static const int en_main = 1;
case 32:
{
if(CBOOL(string_value->tainted_p(state))) tainted = true;
if(CBOOL(string_value->untrusted_p(state))) untrusted = true;
native_int size = string_value->byte_size();
if(rest) count = size;
if(count <= size) {
@@ -3605,7 +3602,6 @@ static const int en_main = 1;
case 32:
{
if(CBOOL(string_value->tainted_p(state))) tainted = true;
if(CBOOL(string_value->untrusted_p(state))) untrusted = true;
native_int size = string_value->byte_size();
if(rest) count = size;
if(count <= size) {
@@ -3769,11 +3765,6 @@ static const int en_main = 1;
tainted = false;
}

if(untrusted) {
result->untrust(state);
untrusted = false;
}

return result;
}
break;
4 changes: 0 additions & 4 deletions machine/instructions.def
Original file line number Diff line number Diff line change
@@ -1580,7 +1580,6 @@ instruction string_build(count) [ +count -- string ]
size_t size = 0;

bool tainted = false;
bool untrusted = false;

bool check_encoding = false;
Encoding* enc = nil<Encoding>();
@@ -1591,7 +1590,6 @@ instruction string_build(count) [ +count -- string ]

if(obj->reference_p()) {
tainted |= obj->is_tainted_p();
untrusted |= obj->is_untrusted_p();
}

String* str = try_as<String>(obj);
@@ -1612,7 +1610,6 @@ instruction string_build(count) [ +count -- string ]
str = obj->to_s(state, false);

tainted |= str->is_tainted_p();
untrusted |= str->is_untrusted_p();
native_int cur_size = str->byte_size();
native_int data_size = as<ByteArray>(str->data())->size();
if(unlikely(cur_size > data_size)) {
@@ -1691,7 +1688,6 @@ instruction string_build(count) [ +count -- string ]
if(!enc->nil_p()) str->encoding(state, enc);

if(tainted) str->set_tainted();
if(untrusted) str->set_untrusted();

stack_clear(count);
stack_push(str);
10 changes: 0 additions & 10 deletions machine/jit/llvm/inline_primitive.cpp
Original file line number Diff line number Diff line change
@@ -1486,14 +1486,6 @@ namespace rubinius {
i.context()->leave_inline();
}

void object_untrusted_p() {
log("Object#untrusted?");
i.context()->enter_inline();
i.set_result(ops.get_header_value(i.recv(), OBJECT_FLAGS_UNTRUSTED, "rbx_is_untrusted"));
i.exception_safe();
i.context()->leave_inline();
}

void proc_call(int count) {
log("Proc#call");
i.context()->enter_inline();
@@ -1665,8 +1657,6 @@ namespace rubinius {
ip.object_frozen_p();
} else if(prim == Primitives::object_tainted_p && count_ == 0) {
ip.object_tainted_p();
} else if(prim == Primitives::object_untrusted_p && count_ == 0) {
ip.object_untrusted_p();
} else if(prim == Primitives::float_add && count_ == 1) {
ip.float_op(cAdd);
} else if(prim == Primitives::float_sub && count_ == 1) {
8 changes: 0 additions & 8 deletions machine/jit/llvm/util.cpp
Original file line number Diff line number Diff line change
@@ -90,10 +90,6 @@ extern "C" {
return obj->frozen_p(state);
}

Object* rbx_is_untrusted(STATE, Object* obj) {
return obj->untrusted_p(state);
}

Object* rbx_is_tainted(STATE, Object* obj) {
return obj->tainted_p(state);
}
@@ -1168,7 +1164,6 @@ extern "C" {
size_t size = 0;

bool tainted = false;
bool untrusted = false;

bool check_encoding = false;
Encoding* enc = nil<Encoding>();
@@ -1179,7 +1174,6 @@ extern "C" {

if(obj->reference_p()) {
tainted |= obj->is_tainted_p();
untrusted |= obj->is_untrusted_p();
}

String* str = try_as<String>(obj);
@@ -1200,7 +1194,6 @@ extern "C" {
str = obj->to_s(state, false);

tainted |= str->is_tainted_p();
untrusted |= str->is_untrusted_p();
native_int cur_size = str->byte_size();
native_int data_size = as<ByteArray>(str->data())->size();
if(unlikely(cur_size > data_size)) {
@@ -1270,7 +1263,6 @@ extern "C" {
if(!enc->nil_p()) str->encoding(state, enc);

if(tainted) str->set_tainted();
if(untrusted) str->set_untrusted();

return str;
}
10 changes: 0 additions & 10 deletions machine/oop.cpp
Original file line number Diff line number Diff line change
@@ -296,16 +296,6 @@ namespace rubinius {
}
}

void ObjectHeader::set_untrusted(int val) {
for(;;) {
HeaderWord orig = header;
HeaderWord new_val = orig;
new_val.f.Untrusted = val;

if(header.atomic_set(orig, new_val)) return;
}
}

void ObjectHeader::clear_handle(STATE) {
for(;;) {
HeaderWord orig = header;
11 changes: 1 addition & 10 deletions machine/oop.hpp
Original file line number Diff line number Diff line change
@@ -169,9 +169,9 @@ Object* const cUndef = reinterpret_cast<Object*>(0x22L);

unsigned int Frozen : 1;
unsigned int Tainted : 1;
unsigned int Untrusted : 1;
unsigned int LockContended : 1;

unsigned int unused : 1;
uint32_t aux_word;
};

@@ -559,15 +559,6 @@ Object* const cUndef = reinterpret_cast<Object*>(0x22L);

void set_tainted(int val=1);

bool is_untrusted_p() const {
if(reference_p()) {
return flags().Untrusted == 1;
}
return false;
}

void set_untrusted(int val=1);

uint32_t object_id(STATE) const {
// Pull this out into a local so that we don't see any concurrent
// changes to header.

0 comments on commit 377d5c9

Please sign in to comment.