summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-29 05:39:03 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-29 05:39:03 (GMT)
commit238394e7384d68627b1faa9a45c95517e9ea47e3 (patch)
tree837f4c9da5f7be9aaa095056885220b80e29343b /util.c
parentd8bbb5eda83f92bfa6045bc5165f7578e524a2f5 (diff)
parse.y: check NTH_REF range
* compile.c (iseq_compile_each): out of range NTH_REF is always nil. * parse.y (parse_numvar): check overflow of NTH_REF and range. [ruby-core:69393] [Bug #11192] * util.c (ruby_scan_digits): make public and add length parameter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/util.c b/util.c
index 807f43f..0319fb5 100644
--- a/util.c
+++ b/util.c
@@ -76,21 +76,25 @@ const signed char ruby_digit36_to_number_table[] = {
/*f*/ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
};
-static unsigned long
-scan_digits(const char *str, int base, size_t *retlen, int *overflow)
+unsigned long
+ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow)
{
const char *start = str;
unsigned long ret = 0, x;
unsigned long mul_overflow = (~(unsigned long)0) / base;
- int c;
+
*overflow = 0;
- while ((c = (unsigned char)*str++) != '\0') {
- int d = ruby_digit36_to_number_table[c];
+ if (!len) {
+ *retlen = 0;
+ return 0;
+ }
+
+ do {
+ int d = ruby_digit36_to_number_table[(unsigned char)*str++];
if (d == -1 || base <= d) {
- *retlen = (str-1) - start;
- return ret;
+ break;
}
if (mul_overflow < ret)
*overflow = 1;
@@ -99,7 +103,7 @@ scan_digits(const char *str, int base, size_t *retlen, int *overflow)
ret += d;
if (ret < x)
*overflow = 1;
- }
+ } while (len < 0 || --len);
*retlen = (str-1) - start;
return ret;
}
@@ -151,7 +155,7 @@ ruby_strtoul(const char *str, char **endptr, int base)
b = base == 0 ? 10 : base;
}
- ret = scan_digits(str, b, &len, &overflow);
+ ret = ruby_scan_digits(str, -1, b, &len, &overflow);
if (0 < len)
subject_found = str+len;