Skip to content
Browse files

Don't crash on Rubinius::Type.infect(0, 0)

  • Loading branch information...
1 parent 7cc9b7c commit 0592c767f8d08db2e8a5f301bf2a461fb1087949 @jfirebaugh jfirebaugh committed Mar 1, 2012
Showing with 40 additions and 2 deletions.
  1. +38 −0 spec/core/type/infect_spec.rb
  2. +2 −2 vm/builtin/object.cpp
View
38 spec/core/type/infect_spec.rb
@@ -0,0 +1,38 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Rubinius::Type.infect" do
+ it "returns the first argument" do
+ a = Object.new
+ b = Object.new
+ Rubinius::Type.infect(a, b).should equal(a)
+ end
+
+ it "doesn't taint the first argument if the second is untainted" do
+ Rubinius::Type.infect(Object.new, Object.new).tainted?.should be_false
+ end
+
+ it "taints the first argument if the second is tainted" do
+ Rubinius::Type.infect(Object.new, Object.new.taint).tainted?.should be_true
+ end
+
+ ruby_version_is "1.9" do
+ it "doesn't untrust the first argument if the second is trusted" do
+ Rubinius::Type.infect(Object.new, Object.new).untrusted?.should be_false
+ end
+
+ it "untrusts the first argument if the second is untrusted" do
+ Rubinius::Type.infect(Object.new, Object.new.untrust).untrusted?.should be_true
+ end
+ end
+
+ it "is a no-op for immediate types" do
+ Rubinius::Type.infect(1, Object.new.taint).tainted?.should be_false
+ Rubinius::Type.infect(:a, Object.new.taint).tainted?.should be_false
+ Rubinius::Type.infect(true, Object.new.taint).tainted?.should be_false
+ Rubinius::Type.infect(false, Object.new.taint).tainted?.should be_false
+ Rubinius::Type.infect(1, 1).tainted?.should be_false
+ Rubinius::Type.infect(:a, :a).tainted?.should be_false
+ Rubinius::Type.infect(true, true).tainted?.should be_false
+ Rubinius::Type.infect(false, false).tainted?.should be_false
+ end
+end
View
4 vm/builtin/object.cpp
@@ -412,12 +412,12 @@ namespace rubinius {
}
void Object::infect(STATE, Object* other) {
- if(is_tainted_p()) {
+ if(tainted_p(state) == cTrue) {
other->taint(state);
}
if(!LANGUAGE_18_ENABLED(state)) {
- if(is_untrusted_p()) {
+ if(untrusted_p(state) == cTrue) {
other->untrust(state);
}
}

0 comments on commit 0592c76

Please sign in to comment.
Something went wrong with that request. Please try again.