]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
util1: handle out-of-range times in timestring
authorAndrew Tridgell <andrew@tridgell.net>
Fri, 15 May 2026 00:27:22 +0000 (10:27 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Wed, 20 May 2026 00:01:22 +0000 (10:01 +1000)
util1.c

diff --git a/util1.c b/util1.c
index 49ead492d50bf99ea66957ef721e069150fa03db..36c1b68cdb744ea61ba7605c581eaba03de60ca9 100644 (file)
--- a/util1.c
+++ b/util1.c
@@ -1459,7 +1459,12 @@ char *timestring(time_t t)
        static char buffers[4][20]; /* We support 4 simultaneous timestring results. */
        char *TimeBuf = buffers[ndx = (ndx + 1) % 4];
        struct tm tmp, *tm = localtime_r(&t, &tmp);
-       int len = snprintf(TimeBuf, sizeof buffers[0], "%4d/%02d/%02d %02d:%02d:%02d",
+       int len;
+       if (!tm) {
+               strlcpy(TimeBuf, "(time out of range)", sizeof buffers[0]);
+               return TimeBuf;
+       }
+       len = snprintf(TimeBuf, sizeof buffers[0], "%4d/%02d/%02d %02d:%02d:%02d",
                 (int)tm->tm_year + 1900, (int)tm->tm_mon + 1, (int)tm->tm_mday,
                 (int)tm->tm_hour, (int)tm->tm_min, (int)tm->tm_sec);
        assert(len > 0); /* Silence gcc warning */