scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 94f23734015424515144b54f0a9f9d6c9d2f34c2
parent b843da74b79d585a30bd2b3f13e7c63d105baf94
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 16 May 2022 11:43:29 +0200

libc: Correct time zone copy in strftime()

Time zone are longer than 3 characters some times, and the
code was not checking the pending size in the buffer and
it could drive to buffer overflow problems.

Diffstat:
Msrc/libc/time/strftime.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/libc/time/strftime.c b/src/libc/time/strftime.c @@ -293,8 +293,13 @@ strftime(char *restrict s, size_t maxsize, inc = timezone(s, n, timeptr); break; case 'Z': - memcpy(s, timeptr->tm_zone, 3); - inc = 3; + inc = strlen(timeptr->tm_zone); + if (inc > n) { + *s = '?'; + inc = 1; + } else { + memcpy(s, timeptr->tm_zone, inc); + } break; case '\0': inc = 0;