Skip to content

Commit

Permalink
Check argument to ObjectSpace._id2ref
Browse files Browse the repository at this point in the history
Ensure that the argument is an Integer or implicitly convert to,
before dereferencing as a Bignum.  Addressed a regression in
b99833b.

Reported by u75615 at https://hackerone.com/reports/898614
  • Loading branch information
nobu committed Jun 16, 2020
1 parent 19cabe8 commit 26c179d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions gc.c
Expand Up @@ -3716,6 +3716,7 @@ id2ref(VALUE objid)
VALUE orig;
void *p0;

objid = rb_to_int(objid);
if (FIXNUM_P(objid) || rb_big_size(objid) <= SIZEOF_VOIDP) {
ptr = NUM2PTR(objid);
if (ptr == Qtrue) return Qtrue;
Expand Down
10 changes: 10 additions & 0 deletions test/ruby/test_objectspace.rb
Expand Up @@ -55,6 +55,16 @@ def test_id2ref_liveness
EOS
end

def test_id2ref_invalid_argument
msg = /no implicit conversion/
assert_raise_with_message(TypeError, msg) {ObjectSpace._id2ref(nil)}
assert_raise_with_message(TypeError, msg) {ObjectSpace._id2ref(false)}
assert_raise_with_message(TypeError, msg) {ObjectSpace._id2ref(true)}
assert_raise_with_message(TypeError, msg) {ObjectSpace._id2ref(:a)}
assert_raise_with_message(TypeError, msg) {ObjectSpace._id2ref("0")}
assert_raise_with_message(TypeError, msg) {ObjectSpace._id2ref(Object.new)}
end

def test_count_objects
h = {}
ObjectSpace.count_objects(h)
Expand Down

0 comments on commit 26c179d

Please sign in to comment.