1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Check argument to ObjectSpace._id2ref

Ensure that the argument is an Integer or implicitly convert to,
before dereferencing as a Bignum.  Addressed a regression in
b99833baec.

Reported by u75615 at https://hackerone.com/reports/898614
This commit is contained in:
Nobuyoshi Nakada 2020-06-16 01:03:15 +09:00
parent 19cabe8b09
commit 26c179d7e7
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 11 additions and 0 deletions

1
gc.c
View file

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

View file

@ -55,6 +55,16 @@ End
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)