summaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-07 06:36:38 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-07 06:36:38 +0000
commit46af6e017599c6db1cfd1629c53cd59c6c410c5b (patch)
tree06b20fb8eb1e8962a7a988b39a1d50c4e0b276e6 /sprintf.c
parenta48345752dfd9d33fa0984f0a131546b7711d706 (diff)
downloadruby-46af6e017599c6db1cfd1629c53cd59c6c410c5b.tar.gz
ruby-46af6e017599c6db1cfd1629c53cd59c6c410c5b.tar.xz
ruby-46af6e017599c6db1cfd1629c53cd59c6c410c5b.zip
* sprintf.c (rb_str_format): integer overflow check added.
* sprintf.c (GETASTER): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@9653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/sprintf.c b/sprintf.c
index c4419259f..07526756f 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -116,6 +116,10 @@ sign_bits(int base, const char *p)
t = p++; \
n = 0; \
for (; p < end && ISDIGIT(*p); p++) { \
+ int times10 = n*10; \
+ if (times10 / 10 != n) {\
+ rb_raise(rb_eArgError, #val " too big"); \
+ } \
n = 10 * n + (*p - '0'); \
} \
if (p >= end) { \
@@ -316,6 +320,10 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
case '5': case '6': case '7': case '8': case '9':
n = 0;
for (; p < end && ISDIGIT(*p); p++) {
+ int times10 = n*10;
+ if (times10 / 10 != n) {
+ rb_raise(rb_eArgError, "width too big");
+ }
n = 10 * n + (*p - '0');
}
if (p >= end) {
@@ -337,7 +345,6 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (flags & FWIDTH) {
rb_raise(rb_eArgError, "width given twice");
}
-
flags |= FWIDTH;
GETASTER(width);
if (width < 0) {