Skip to content

Commit 8f72681

Browse files
committed
* bignum.c (rb_cstr_to_inum): check leading non-digits.
[ruby-core:11691] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@13174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent d47a440 commit 8f72681

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Wed Aug 22 10:11:59 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* bignum.c (rb_cstr_to_inum): check leading non-digits.
4+
[ruby-core:11691]
5+
16
Wed Aug 22 10:07:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
27

38
* bignum.c (rb_big_neg): SIGNED_VALUE isn't in 1.8.

bignum.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ rb_cstr_to_inum(str, base, badcheck)
346346
VALUE z;
347347
BDIGIT *zds;
348348

349+
#define conv_digit(c) \
350+
(!ISASCII(c) ? -1 : \
351+
isdigit(c) ? ((c) - '0') : \
352+
islower(c) ? ((c) - 'a' + 10) : \
353+
isupper(c) ? ((c) - 'A' + 10) : \
354+
-1)
355+
349356
if (!str) {
350357
if (badcheck) goto bad;
351358
return INT2FIX(0);
@@ -438,7 +445,13 @@ rb_cstr_to_inum(str, base, badcheck)
438445
}
439446
if (*str == '0') { /* squeeze preceeding 0s */
440447
while (*++str == '0');
441-
--str;
448+
if (!*str) --str;
449+
}
450+
c = *str;
451+
c = conv_digit(c);
452+
if (c < 0 || c >= base) {
453+
if (badcheck) goto bad;
454+
return INT2FIX(0);
442455
}
443456
len *= strlen(str)*sizeof(char);
444457

@@ -472,27 +485,15 @@ rb_cstr_to_inum(str, base, badcheck)
472485
z = bignew(len, sign);
473486
zds = BDIGITS(z);
474487
for (i=len;i--;) zds[i]=0;
475-
while (c = *str++) {
488+
while ((c = *str++) != 0) {
476489
if (c == '_') {
477490
if (badcheck) {
478491
if (nondigit) goto bad;
479492
nondigit = c;
480493
}
481494
continue;
482495
}
483-
else if (!ISASCII(c)) {
484-
break;
485-
}
486-
else if (isdigit(c)) {
487-
c -= '0';
488-
}
489-
else if (islower(c)) {
490-
c -= 'a' - 10;
491-
}
492-
else if (isupper(c)) {
493-
c -= 'A' - 10;
494-
}
495-
else {
496+
else if ((c = conv_digit(c)) < 0) {
496497
break;
497498
}
498499
if (c >= base) break;

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define RUBY_RELEASE_DATE "2007-08-22"
33
#define RUBY_VERSION_CODE 186
44
#define RUBY_RELEASE_CODE 20070822
5-
#define RUBY_PATCHLEVEL 63
5+
#define RUBY_PATCHLEVEL 64
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8

0 commit comments

Comments
 (0)