Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the mrb_get_args() function #5540

Merged
merged 1 commit into from Aug 28, 2021
Merged

Conversation

dearblue
Copy link
Contributor

  • Removed the ARGV macro.
    The current path doesn't go into the mruby VM and there's also no need to separate variables.
  • Use common functions to check object types.
    • Use mrb_ensure_string_type() to check the string instead of mrb_to_str().
      This is for consistency with array and hash.
    • Use mrb_ensure_array_type() to check the array instead of to_ary().
    • Use mrb_ensure_hash_type() to check the hash instead of to_hash().
    • Add and use ensure_class_type() to check class and module.
  • Changed the argument index type from mrb_int to int.
    Even if it is int16_t, it is enough.
    mrb_int is overkill, especially if MRB_32BIT and MRB_INT64 are defined.

- Removed the `ARGV` macro.
  The current path doesn't go into the mruby VM and there's also no need to separate variables.
- Use common functions to check object types.
  - Use `mrb_ensure_string_type()` to check the string instead of `mrb_to_str()`.
    This is for consistency with array and hash.
  - Use `mrb_ensure_array_type()` to check the array instead of `to_ary()`.
  - Use `mrb_ensure_hash_type()` to check the hash instead of `to_hash()`.
  - Add and use `ensure_class_type()` to check class and module.
- Changed the argument index type from `mrb_int` to `int`.
  Even if it is `int16_t`, it is enough.
  `mrb_int` is overkill, especially if `MRB_32BIT` and `MRB_INT64` are defined.
@dearblue dearblue requested a review from matz as a code owner August 27, 2021 13:58
@matz matz merged commit 07f12fe into mruby:master Aug 28, 2021
@dearblue dearblue deleted the mrb_get_args branch August 28, 2021 06:56
dearblue added a commit to dearblue/mruby that referenced this pull request Dec 30, 2021
ref. mruby#5613.

I mentioned in mruby#5540 that there was no reentrant to the virtual machine, but in fact it was still a possibility at that point.
Also, the variable `ci` needs to be recalculated at the same time.
matz added a commit that referenced this pull request Dec 31, 2021
It should only call `to_f` for Rational and Complex numbers.
Ref #5540 #5613 #5620
iwamatsu pushed a commit to mruby-debian/mruby that referenced this pull request Jun 25, 2023
ref. mruby#5613.

I mentioned in mruby#5540 that there was no reentrant to the virtual
machine, but in fact it was still a possibility at that point.
Also, the variable `ci` needs to be recalculated at the same time.

[iwamatsu]
  backport to 3.0.0. This commit had been reverted by
  mruby@dfa21f2
  in upstream. But However, this is because MR mruby#5622 merged the function. The
  patch is valid.
Reference: CVE-2021-46020
Reference: mruby#5613
Reference: mruby@d3b7601
Reference: mruby#5620
Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants