summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-07 14:40:07 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-07 14:40:07 +0000
commit4a5a6f4a2c6a20fb61ab834655fdae8ba4879196 (patch)
treee18fe99e6a2e828026bc38d6e952605509ffebcf
parent86411a0a761976b6d4ec9d0d841e727f17495c78 (diff)
merge revision(s) 32885:
* time.c (rb_strftime_alloc): raise ERANGE if width is too large. Patch by Nobuyoshi Nakada. [Bug #4457] [ruby-dev:43285] * test/ruby/test_time.rb (class TestTime): add a test for the above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--test/ruby/test_time.rb3
-rw-r--r--time.c6
3 files changed, 16 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4f9dc01a6d..b2eeff9845 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sun Aug 7 23:39:44 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
+
+ * time.c (rb_strftime_alloc): raise ERANGE if width is too large.
+ Patch by Nobuyoshi Nakada. [Bug #4457] [ruby-dev:43285]
+
+ * test/ruby/test_time.rb (class TestTime): add a test for the
+ above change.
+
Sun Aug 7 14:15:10 2011 Kazuki Tsujimoto <kazuki@callcc.net>
* backport r32876 from trunk.
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index aea4c2edc0..0e61f32ab0 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -649,6 +649,9 @@ class TestTime < Test::Unit::TestCase
# [ruby-core:33985]
assert_equal("3000000000", Time.at(3000000000).strftime('%s'))
+
+ bug4457 = '[ruby-dev:43285]'
+ assert_raise(Errno::ERANGE, bug4457) {Time.now.strftime('%8192z')}
end
def test_delegate
diff --git a/time.c b/time.c
index b2e3448610..5122466675 100644
--- a/time.c
+++ b/time.c
@@ -4326,8 +4326,12 @@ rb_strftime_alloc(char **buf, const char *format,
* if the buffer is 1024 times bigger than the length of the
* format string, it's not failing for lack of room.
*/
- if (len > 0 || size >= 1024 * flen) break;
+ if (len > 0) break;
xfree(*buf);
+ if (size >= 1024 * flen) {
+ rb_sys_fail(format);
+ break;
+ }
}
return len;
}