aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-04 06:12:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-04 06:12:12 +0000
commit955849c126dedaab1d5f3a5467f3daf3da16d14d (patch)
treeda02d7d2cbe1f096febfc7e0823df275d5f84c42 /object.c
parent6dd4657fc2bbbb1aad36afc24dcb19553fd41ab6 (diff)
downloadruby-955849c126dedaab1d5f3a5467f3daf3da16d14d.tar.gz
object.c: raise on long invalid float string
* object.c (rb_cstr_to_dbl_raise): check long invalid float string more precisely when truncating insignificant part. [ruby-core:86800] [Bug #14729] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/object.c b/object.c
index a4594a2982..7a9ee001e6 100644
--- a/object.c
+++ b/object.c
@@ -3273,7 +3273,13 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error)
char *const init_e = buf + DBL_DIG * 4;
char *e = init_e;
char prev = 0;
+ int dot_seen = FALSE;
+ switch (*p) {case '+': case '-': prev = *n++ = *p++;}
+ if (*p == '0') {
+ prev = *n++ = '0';
+ while (*++p == '0');
+ }
while (p < end && n < e) prev = *n++ = *p++;
while (*p) {
if (*p == '_') {
@@ -3284,8 +3290,26 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error)
}
}
prev = *p++;
- if (e == init_e && (*p == 'e' || *p == 'E')) {
+ if (e == init_e && (prev == 'e' || prev == 'E' || prev == 'p' || prev == 'P')) {
e = buf + sizeof(buf) - 1;
+ *n++ = prev;
+ switch (*p) {case '+': case '-': prev = *n++ = *p++;}
+ if (*p == '0') {
+ prev = *n++ = '0';
+ while (*++p == '0');
+ }
+ continue;
+ }
+ else if (ISSPACE(prev)) {
+ while (ISSPACE(*p)) ++p;
+ if (*p) {
+ if (badcheck) goto bad;
+ break;
+ }
+ }
+ else if (prev == '.' ? dot_seen++ : !ISDIGIT(prev)) {
+ if (badcheck) goto bad;
+ break;
}
if (n < e) *n++ = prev;
}