diff options
author | Dan Albert <danalbert@google.com> | 2014-10-07 18:38:11 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-10-07 18:38:11 +0000 |
commit | eeb9aa02b7f307a1d9b80731dd69ef9dd2f47e47 (patch) | |
tree | e1f6074157470da7a594f3f3d4300265332f271a | |
parent | 6d2dd6a74035a7ace838dd44e7910d54e15c11c2 (diff) | |
parent | b0fd55608e707b3e9b5c2937537414be7d098afd (diff) | |
download | bionic-eeb9aa02b7f307a1d9b80731dd69ef9dd2f47e47.zip bionic-eeb9aa02b7f307a1d9b80731dd69ef9dd2f47e47.tar.gz bionic-eeb9aa02b7f307a1d9b80731dd69ef9dd2f47e47.tar.bz2 |
Merge "Use snprintf instead of sprintf."
-rw-r--r-- | libc/bionic/time64.c | 18 |
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, |