Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #102 from jruby/marshal_jruby_security

Add and reorg Marshal#load specs from JRuby security bugs.
  • Loading branch information...
commit d46445b097f01676ed776e1f37d448a1475b74e2 2 parents b11338c + 8f1d099
@brixen brixen authored
Showing with 23 additions and 17 deletions.
  1. +23 −17 core/marshal/load_spec.rb
View
40 core/marshal/load_spec.rb
@@ -400,6 +400,12 @@
it "loads a object" do
Marshal.load("\004\bo:\vObject\000").should be_kind_of(Object)
end
+
+ it "raises ArgumentError if the object from an 'o' stream is not dumpable as 'o' type user class" do
+ lambda do
+ Marshal.load("\x04\bo:\tFile\001\001:\001\005@path\"\x10/etc/passwd")
+ end.should raise_error(ArgumentError)
+ end
it "loads an extended Object" do
obj = Object.new.extend(Meths)
@@ -410,6 +416,23 @@
new_obj_metaclass_ancestors = class << new_obj; ancestors; end
new_obj_metaclass_ancestors.first(2).should == [Meths, Object]
end
+
+ describe "that extends a core type other than Object or BasicObject" do
+ after :each do
+ MarshalSpec.reset_swapped_class
+ end
+
+ it "raises ArgumentError if the resulting class does not extend the same type" do
+ MarshalSpec.set_swapped_class(Class.new(Hash))
+ data = Marshal.dump(MarshalSpec::SwappedClass.new)
+
+ MarshalSpec.set_swapped_class(Class.new(Array))
+ lambda { Marshal.load data }.should raise_error(ArgumentError)
+
+ MarshalSpec.set_swapped_class(Class.new)
+ lambda { Marshal.load data }.should raise_error(ArgumentError)
+ end
+ end
it "loads a object having ivar" do
s = 'hi'
@@ -544,21 +567,4 @@
lambda { Marshal.load data }.should raise_error(ArgumentError)
end
end
-
- describe "unmarshalling an object that was a user-defined subclass of a type other than Object" do
- after :each do
- MarshalSpec.reset_swapped_class
- end
-
- it "raises ArgumentError if the current class is not the same structure" do
- MarshalSpec.set_swapped_class(Class.new(Hash))
- data = Marshal.dump(MarshalSpec::SwappedClass.new)
-
- MarshalSpec.set_swapped_class(Class.new(Array))
- lambda { Marshal.load data }.should raise_error(ArgumentError)
-
- MarshalSpec.set_swapped_class(Class.new)
- lambda { Marshal.load data }.should raise_error(ArgumentError)
- end
- end
end
Please sign in to comment.
Something went wrong with that request. Please try again.