summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro Matz Matsumoto <[email protected]>2013-03-14 23:12:21 +0900
committerYukihiro Matz Matsumoto <[email protected]>2013-03-14 23:12:21 +0900
commit08a0c9f32843d4ebe17476608d6b2f3d8d703313 (patch)
tree90d74c4aeeec1c165f36b2bfc05563f4333252dd /src
parent228687cfff7aed676c9fc02fa587bd74ed097489 (diff)
downloadmruby-08a0c9f32843d4ebe17476608d6b2f3d8d703313.tar.gz
mruby-08a0c9f32843d4ebe17476608d6b2f3d8d703313.zip
add mrb_int overflow check for mrb_int
Diffstat (limited to 'src')
-rw-r--r--src/string.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/string.c b/src/string.c
index cd70e63f6..d474f6f96 100644
--- a/src/string.c
+++ b/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++;