From 7bb73a0852c747478ff5ed030e2a857d201596b7 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 3 Mar 2011 05:28:00 +0000 Subject: [PATCH] * strftime.c (STRFTIME): return 0 and ERANGE when precision is too large. [ruby-dev:43284] fixes #4456 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ strftime.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index afcd6ac09d..101fb3bcd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Mar 3 14:25:19 2011 NARUSE, Yui + + * strftime.c (STRFTIME): return 0 and ERANGE when precision is too + large. [ruby-dev:43284] fixes #4456 + Thu Mar 3 00:46:51 2011 NARUSE, Yui * addr2line.c (uleb128): cast the value to unsigned long. diff --git a/strftime.c b/strftime.c index dc6df615d7..9d9f48d0de 100644 --- a/strftime.c +++ b/strftime.c @@ -237,6 +237,10 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const str i = rb_strftime_with_timespec(s, endp - s, (fmt), vtm, timev, ts, gmt); \ if (!i) return 0; \ if (precision > i) {\ + if (start + maxsize < s + precision) { \ + errno = ERANGE; \ + return 0; \ + } \ memmove(s + precision - i, s, i);\ memset(s, padding ? padding : ' ', precision - i); \ s += precision; \