mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-data/data.c (mrb_data_ref): avoid out-of-bound access
This commit is contained in:
@@ -101,9 +101,11 @@ mrb_data_ref(mrb_state *mrb, mrb_value obj)
|
||||
mrb_argnum_error(mrb, argc, 0, 0);
|
||||
}
|
||||
mrb_int i = mrb_integer(mrb_proc_cfunc_env_get(mrb, 0));
|
||||
mrb_int len = RDATA_LEN(obj);
|
||||
mrb_value *ptr = RDATA_PTR(obj);
|
||||
|
||||
if (!ptr) return mrb_nil_value();
|
||||
if (!ptr || len <= i)
|
||||
return mrb_nil_value();
|
||||
return ptr[i];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user