summaryrefslogtreecommitdiffstats
path: root/libc/bionic/time64.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/bionic/time64.c')
-rw-r--r--libc/bionic/time64.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/libc/bionic/time64.c b/libc/bionic/time64.c
index 95dfab5..da38bf3 100644
--- a/libc/bionic/time64.c
+++ b/libc/bionic/time64.c
@@ -748,10 +748,24 @@ static int valid_tm_mon( const struct TM* date ) {
char *asctime64_r( const struct TM* date, char *result ) {
/* I figure everything else can be displayed, even hour 25, but if
these are out of range we walk off the name arrays */
- if( !valid_tm_wday(date) || !valid_tm_mon(date) )
+ if (!valid_tm_wday(date) || !valid_tm_mon(date)) {
return NULL;
+ }
+
+ /* Docs state this function does not support years beyond 9999. */
+ if (1900 + date->tm_year > 9999) {
+ return NULL;
+ }
- sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
+ /*
+ * The IBM docs for this function state that the result buffer can be
+ * assumed to be at least 26 bytes wide. The docs also state that this is
+ * only valid for years <= 9999, so we know this format string will not
+ * print more than that many characters.
+ *
+ * http://www-01.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxbd00/asctimer.htm
+ */
+ snprintf(result, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
wday_name[date->tm_wday],
mon_name[date->tm_mon],
date->tm_mday, date->tm_hour,