diff options
Diffstat (limited to 'ext/date/date_strftime.c')
| -rw-r--r-- | ext/date/date_strftime.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/ext/date/date_strftime.c b/ext/date/date_strftime.c index 87cb0a7ddd..d7f28989d6 100644 --- a/ext/date/date_strftime.c +++ b/ext/date/date_strftime.c @@ -12,6 +12,10 @@ #include <ctype.h> #include <errno.h> +#if defined(HAVE_SYS_TIME_H) +#include <sys/time.h> +#endif + #undef strchr /* avoid AIX weirdness */ #define range(low, item, hi) (item) @@ -44,7 +48,7 @@ downcase(char *s, size_t i) /* strftime --- produce formatted time */ static size_t -date_strftime_with_tmx(char *s, size_t maxsize, const char *format, +date_strftime_with_tmx(char *s, const size_t maxsize, const char *format, const struct tmx *tmx) { char *endp = s + maxsize; @@ -53,7 +57,8 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format, auto char tbuf[100]; ptrdiff_t i; int v, w; - int precision, flags, colons; + size_t colons; + int precision, flags; char padding; /* LOCALE_[OE] and COLONS are actually modifiers, not flags */ enum {LEFT, CHCASE, LOWER, UPPER, LOCALE_O, LOCALE_E, COLONS}; @@ -346,7 +351,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format, i = 2; break; - case 'Q': /* microseconds since Unix epoch */ + case 'Q': /* milliseconds since Unix epoch */ FMTV('0', 1, "d", tmx_msecs); continue; @@ -388,7 +393,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format, continue; case 'v': - STRFTIME("%e-%b-%Y"); + STRFTIME("%e-%^b-%Y"); continue; case 'w': /* weekday, Sunday == 0, 0 - 6 */ @@ -570,7 +575,12 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format, case '5': case '6': case '7': case '8': case '9': { char *e; - precision = (int)strtoul(format, &e, 10); + unsigned long prec = strtoul(format, &e, 10); + if (prec > INT_MAX || prec > maxsize) { + errno = ERANGE; + return 0; + } + precision = (int)prec; format = e - 1; goto again; } |
