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:
parent
19cabe8b09
commit
26c179d7e7
2 changed files with 11 additions and 0 deletions
1
gc.c
1
gc.c
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue