Yukihiro "Matz" Matsumoto
d0780c0525
vm.c: should cast bigint length to unsigned.
...
Otherwise length>127 would be considered as negative.
2022-07-28 15:21:32 +09:00
Yukihiro "Matz" Matsumoto
3d1b5d2b06
Merge pull request #5754 from artichoke/lopopolo/class-name-use-after-free
...
Fix possible use after free in `mrb_class_find_path`
2022-07-25 15:41:07 +09:00
Yukihiro "Matz" Matsumoto
13d909bd3c
array.c: new configuration MRB_ARY_LENGTH_MAX.
...
The default value is 2**17 entries. If you want to avoid the limitation,
set this value to 0.
2022-07-25 10:58:02 +09:00
Yukihiro "Matz" Matsumoto
c4cb416460
string.c: new configuration MRB_STR_LENGTH_MAX.
...
The default value is 1MB. If you want to avoid the limitation, set this
value to 0.
2022-07-25 10:58:02 +09:00
Ryan Lopopolo
547d465340
Fix possible use after free in mrb_class_find_path
...
`mrb_class_find_path` resolves a `char*` pointer to a class name string
by calling `mrb_class_name`. It then allocates a new string with
capacity 40 to copy that `char*` into.
https://github.com/mruby/mruby/blob/e04184185ab43b94980550e850d8813a415fa438/src/variable.c#L1111-L1112
`mrb_class_name` resolves the class name via `class_name_str`, which
returns an `mrb_value` with type tag `MRB_TT_STRING` and backed by an
`RString*`. Then `mrb_class_name` extracts the `RSTRING_PTR`:
https://github.com/mruby/mruby/blob/e04184185ab43b94980550e850d8813a415fa438/src/class.c#L2133-L2134
That `RString*`-backed `mrb_value` ultimately comes from `mrb_class_path`
which resolves the string from the symbol table:
https://github.com/mruby/mruby/blob/e04184185ab43b94980550e850d8813a415fa438/src/class.c#L2111
The allocation of the target `str` after resolving the class name
`mrb_value` and extracting its pointer is fragile and assumes the
`RString*` is "static". If the `RString*` is not static, the
interleaving of extracting the `RSTRING_PTR` followed by a subsequent
allocation might result in the class name `mrb_value` being garbage
collected, which will leave the extracted pointer invalid.
Fix this bad interleaving by allocating the destination string first
before taking a raw pointer to an `RString*`.
2022-07-24 09:33:51 -07:00
Yukihiro "Matz" Matsumoto
a3f2470907
Merge pull request #5749 from dearblue/patch-5565
...
Corrected the number of registers in the `Class#new` method
2022-07-18 09:26:34 +09:00
Yukihiro "Matz" Matsumoto
0e530dbb63
numeric.c: fix smallint op bigint error in bitwise logical operators.
2022-07-18 08:29:52 +09:00
dearblue
c621d3cb95
Corrected the number of registers in the Class#new method
...
`OP_SEND R4 :allocate 0` requires an an invisible `nil` block to `R5`.
If `R5` is not allocated, this can lead to unexpected results due to buffer overflow.
This problem is caused by #5565 .
ref. commit 33792c2a02
2022-07-17 10:38:53 +09:00
Yukihiro "Matz" Matsumoto
37c2f080f0
numeric.c (int_to_s): should not bypass base range check.
2022-07-12 14:48:36 +09:00
Yukihiro "Matz" Matsumoto
bae11ef689
complex.c (mrb_complex_copy): allow copying of complex numbers.
2022-07-11 11:25:31 +09:00
Yukihiro "Matz" Matsumoto
67f47c9b42
rational.c (mrb_rational_copy): allow copying of rational numbers.
2022-07-11 11:19:22 +09:00
Yukihiro "Matz" Matsumoto
3ebb55b75f
bigint.c (mrb_bint_copy): allow dup operation for bigints.
2022-07-11 11:02:27 +09:00
Yukihiro "Matz" Matsumoto
48b43af37f
numeric.c (mrb_div_int_value): should support integer overflow.
...
Especially in `MRB_INT_MIN/-1` which is bigger than MRB_INT_MAX.
2022-07-09 15:21:45 +09:00
Yukihiro "Matz" Matsumoto
fa0ff7cf86
numeric.c: better error message (Float -> Integer).
2022-07-09 15:13:52 +09:00
Yukihiro "Matz" Matsumoto
7de03cbb68
numeric.c: add mrb_noreturn qualifier to error functions.
...
- mrb_int_zerodiv()
- mrb_int_overflow()
2022-07-09 15:12:37 +09:00
Yukihiro "Matz" Matsumoto
e1980d7596
numeric.c (mrb_div_int): separate the function in two.
...
- mrb_div_int() does integer division in Ruby way (mdiv)
returns mrb_int
- mrb_div_int_value() division with zero div and overflow checks.
returns mrb_value
2022-07-09 14:38:18 +09:00
Yukihiro "Matz" Matsumoto
a2f0fd81e6
numeric.c (mrb_int_mul): fix error message (Float -> Integer).
2022-07-09 10:45:44 +09:00
Yukihiro "Matz" Matsumoto
8d34981530
numeric.c: avoid mathematical operations for simple cases.
2022-07-09 10:45:11 +09:00
Yukihiro "Matz" Matsumoto
960021e519
numeric.c (cmpnum): call mrb_bigint_cmp() if v1 is bigint, not v2.
2022-07-08 21:57:05 +09:00
Yukihiro "Matz" Matsumoto
b5538eded1
vm.c (OP_ENTER): need to protect kdict from GC; ref #5741
2022-07-06 14:57:06 +09:00
Yukihiro "Matz" Matsumoto
8fed80f5eb
vm.c (OP_ENTER): protect kdict from GC; ref #5741
2022-07-06 14:29:14 +09:00
Yukihiro "Matz" Matsumoto
4225ae4176
vm.c (OP_ENTER): need to update ci->nk when kd is set; fix #5741
2022-07-06 13:57:12 +09:00
Yukihiro "Matz" Matsumoto
7e8a4212fb
vm.c: refactor OP_ENTER code; ref #5741
2022-07-06 13:37:29 +09:00
Yukihiro "Matz" Matsumoto
82a419cde3
vm.c (mrb_ci_kdict): should return -1 when no kargs given; ref #5741
2022-07-06 13:37:20 +09:00
Yukihiro "Matz" Matsumoto
638356af03
class.c (mc_clear_by_id): clear method cache with method id specified.
2022-07-05 17:39:36 +09:00
Yukihiro "Matz" Matsumoto
a99e4a926d
class.c (mrb_mc_clear_by_class): simplify method cache clear condition.
2022-07-05 17:39:30 +09:00
Yukihiro "Matz" Matsumoto
1e7012f8c1
class.c (mrb_class_inherited): no need to clear method cache.
...
Since the function is only called for a newly created class, there is no
need to modify the method cache here.
2022-07-04 21:47:19 +09:00
Yukihiro "Matz" Matsumoto
e8a202d461
vm.c: inline callinfo related functions.
2022-07-04 21:15:42 +09:00
Yukihiro "Matz" Matsumoto
03ae46e88d
string.c: keep values in local variables to reduce member access.
2022-06-30 10:12:24 +09:00
Yukihiro "Matz" Matsumoto
f2bc7c305a
array.c (mrb_assoc_new): keep pointer in a local variable.
...
The optimizer may do the same, but tried to make it clear.
2022-06-30 10:09:34 +09:00
Yukihiro "Matz" Matsumoto
e2c4a8cef0
array.c (ary_check_too_big): make the function inline.
2022-06-30 09:57:30 +09:00
Yukihiro "Matz" Matsumoto
580af1cf73
vm.c (mrb_bidx): avoid repeated packing/unpacking argument info.
2022-06-29 07:51:08 +09:00
Yukihiro "Matz" Matsumoto
0b7822581f
string.c (str_rindex): use more local variables; ref #5734
2022-06-27 19:04:36 +09:00
Yukihiro "Matz" Matsumoto
7319e744ad
src/vm.c: move some inline functions from mruby/proc.h; ref #5732
...
Those functions are seldom called so no need to be inline functions.
2022-06-27 19:04:35 +09:00
Stephen Jothen
103f8bcad0
Fix out of bounds access by memcmp in String#rindex
2022-06-25 15:09:35 +02:00
Yukihiro "Matz" Matsumoto
a3ccda657e
Merge pull request #5733 from dearblue/patch-5402
...
Do not expand "included class" in `mrb_proc_new()`.
2022-06-25 14:48:02 +09:00
dearblue
8bab20ef7c
Do not expand "included class" in mrb_proc_new().
...
If `target_class->tt` is `MRB_TT_ICLASS`, it may cause loss of class inheritance relationships.
This problem is caused by #5402 .
ref. #5725
2022-06-25 11:45:18 +09:00
dearblue
1489338145
Use mrb->object_class instead if MRB_PROC_TARGET_CLASS() is NULL
...
Fix #5725
2022-06-25 11:10:39 +09:00
Ryan Lopopolo
8a5e6f47f2
Match #if at end of vm.c
2022-06-23 22:25:15 -07:00
Ryan Lopopolo
3af82fbb51
Respect MRB_USE_CXX_ABI #define
2022-06-23 21:54:53 -07:00
Ryan Lopopolo
c4c37b2069
Fix mismatched braces in extern "C" blocks when compiling as C++
...
When compiling mruby with `-DMRB_USE_CXX_EXCEPTION`, clang fails to
compile and emits these warnings:
vendor/mruby/src/vm.c:3066:1: error: extraneous closing brace ('}')
} /* end of extern "C" */
^
vendor/mruby/src/vm.c:3072:7: error: expected '}'
#endif
^
vendor/mruby/src/vm.c:3070:12: note: to match this '{'
extern "C" {
^
2 errors generated.
Fixup the implementation of the `extern "C"` block in `vm.c`.
2022-06-23 21:38:55 -07:00
Yukihiro "Matz" Matsumoto
92be161b1f
vm.c (check_target_class): return Object class if target is NULL.
...
Since #5272 target_class kept in a Proc may be NULL. It crashes
`iij/mruby-require` gem for example; close #5725
2022-06-23 07:54:04 +09:00
Yukihiro "Matz" Matsumoto
d2a24a540c
hash.c: implement typical part of merge in C.
2022-06-19 22:28:31 +09:00
dearblue
cbeb392d7d
Fixed possible inconsistency in gc_protect()
...
If `mrb_realloc()` raises an out-of-memory exception, `arena_capa` will hold the wrong value.
2022-06-14 22:31:45 +09:00
dearblue
56c6dde9c5
Asigns table properties after mrb_calloc()
...
If GC occurs in `mrb_calloc()` called by `iv_rehash()` or `mt_rehash()`, the object as table data may be destroyed.
2022-06-08 22:10:58 +09:00
Yukihiro "Matz" Matsumoto
8981b2fb28
vm.c (ary_new_from_regs): stack may be reallocated.
...
Unlike `hash_new_from_regs`, `ary_new_from_regs` do not call
`mrb_funcall` et al directly or indirectly. But since it may invoke the
garbage collection, and hooks for GC may call `mrb_funcall` etc (although
calling them is not encouraged), we care stack reallocation just for the
safety.
2022-05-30 11:52:12 +09:00
Yukihiro "Matz" Matsumoto
aa7f98dedb
vm.c (hash_new_from_regs): stack may be reallocated.
2022-05-30 01:18:15 +09:00
Yukihiro "Matz" Matsumoto
82b87be4df
string.c (mrb_utf8len): retry 7cdef2b0.
...
C++ requires `extern` declaration before variable definition.
2022-05-29 22:18:59 +09:00
dearblue
23611332d9
Introduced mrb_static_assert_object_size()
...
Asserts the size of the object structure is less than or equal to 6 words.
2022-05-28 11:08:27 +09:00
Yukihiro "Matz" Matsumoto
82f0ba14a9
Revert "string.c: share UTF-8 length table with mruby-string-ext."
...
This reverts commit 7cdef2b03e .
This sharing does not with C++ compilers.
2022-05-25 16:07:52 +09:00