diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-10-17 07:43:35 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-10-17 07:43:35 +0900 |
| commit | fb85855fa136d215533cac3714ddb99a61531fb8 (patch) | |
| tree | 90c3066c110d0caf13db254deb0f4c6f3e39c83e /mrbgems/mruby-struct | |
| parent | be2c1592ed93bded66c461f236107b4fec6dca7c (diff) | |
| download | mruby-fb85855fa136d215533cac3714ddb99a61531fb8.tar.gz mruby-fb85855fa136d215533cac3714ddb99a61531fb8.zip | |
Add more checks before accessing struct pointer; ref #3831
Diffstat (limited to 'mrbgems/mruby-struct')
| -rw-r--r-- | mrbgems/mruby-struct/src/struct.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index f9127c6fb..fed9e8105 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -147,11 +147,13 @@ static mrb_value mrb_struct_set_m(mrb_state *mrb, mrb_value obj) { mrb_int i = mrb_fixnum(mrb_proc_cfunc_env_get(mrb, 0)); - mrb_value *ptr = RSTRUCT_PTR(obj); + mrb_value *ptr; mrb_value val; + mrb_get_args(mrb, "o", &val); mrb_struct_modify(mrb, obj); - if (i >= RSTRUCT_LEN(obj)) { + ptr = RSTRUCT_PTR(obj); + if (ptr == NULL || i >= RSTRUCT_LEN(obj)) { mrb_ary_set(mrb, obj, i, val); } else { |
