mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
string.c: fix integer overflow in str_check_length()
Reject MRB_INT_MAX length strings to prevent signed integer overflow when adding 1 for the null terminator in str_init_normal_capa() and resize_capa(). Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -40,7 +40,7 @@ const char mrb_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
static void
|
||||
str_check_length(mrb_state *mrb, mrb_int len)
|
||||
{
|
||||
if (len < 0) {
|
||||
if (len < 0 || len == MRB_INT_MAX) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative (or overflowed) string size");
|
||||
}
|
||||
#if MRB_STR_LENGTH_MAX != 0
|
||||
|
||||
Reference in New Issue
Block a user