merge revision(s) 50671: [Backport #11192]

* 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/branches/ruby_2_2@51134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2015-07-03 19:57:42 +00:00
parent 8ff3a728ae
commit 72fa2ec34a
7 changed files with 58 additions and 15 deletions

22
util.c
View file

@ -74,21 +74,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;
@ -97,7 +101,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;
}
@ -149,7 +153,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;