Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add mrb_int overflow check for mrb_int

  • Loading branch information...
commit 08a0c9f32843d4ebe17476608d6b2f3d8d703313 1 parent 228687c
@matz matz authored
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/string.c
View
8 src/string.c
@@ -2050,6 +2050,7 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck)
char *end;
char sign = 1;
int c;
+ unsigned int n;
mrb_int val;
#undef ISDIGIT
@@ -2154,8 +2155,11 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck)
return mrb_fixnum_value(0);
}
- val = strtoul((char*)str, &end, base);
-
+ n = strtoul((char*)str, &end, base);
+ if (n > MRB_INT_MAX) {
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "string (%s) too big for integer", str);
+ }
+ val = n;
if (badcheck) {
if (end == str) goto bad; /* no number */
while (*end && ISSPACE(*end)) end++;
Please sign in to comment.
Something went wrong with that request. Please try again.