aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 c0eb46044a..1d74a2ba72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sun Aug 7 23:31:32 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 22:51:45 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* ext/openssl/ossl_asn1.c (decode_eoc): remove unused variables.
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 38e567a703..1f07a8249c 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -650,6 +650,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 dd846a630c..6817c75e1e 100644
--- a/time.c
+++ b/time.c
@@ -4325,8 +4325,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;
}