From a1172690a00a980b50726119e346e84813d4fcf6 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 16 Jan 2023 16:56:26 -1000 Subject: [PATCH] FIO: Avoid potential buffer overrun while formatting file modify time Silence over aggressive compiler warning. --- sim_fio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sim_fio.c b/sim_fio.c index b600b914..d0b48368 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -1474,7 +1474,7 @@ char *c, *name, *ext; char chr; const char *p; char filesizebuf[32] = ""; -char filedatetimebuf[32] = ""; +char filedatetimebuf[64] = ""; char namebuf[PATH_MAX + 1]; @@ -1553,7 +1553,7 @@ if (strchr (parts, 't') || /* modification time or */ else sprintf (filesizebuf, "%" LL_FMT "d ", (LL_TYPE)filestat.st_size); tm = localtime (&filestat.st_mtime); - sprintf (filedatetimebuf, "%02d/%02d/%04d %02d:%02d %cM ", 1 + tm->tm_mon, tm->tm_mday, 1900 + tm->tm_year, + snprintf (filedatetimebuf, sizeof (filedatetimebuf), "%02d/%02d/%04d %02d:%02d %cM ", 1 + tm->tm_mon, tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour % 12, tm->tm_min, (0 == (tm->tm_hour % 12)) ? 'A' : 'P'); } for (p = parts; *p; p++) {