From: biubiuzy <294772273@qq.com> Date: Fri, 23 Feb 2024 09:44:12 +0000 (+0800) Subject: last: avoid out of bounds array access X-Git-Tag: v2.40~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c706b31e8fa42ccdb19588f36569f6799ba71323;p=thirdparty%2Futil-linux.git last: avoid out of bounds array access (cherry picked from commit 75822efb8e948b538d9e9ccc329a5430fdabb7ea) --- diff --git a/login-utils/last.c b/login-utils/last.c index bbbe817f8..f5a9fec08 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -351,7 +351,10 @@ static int time_formatter(int fmt, char *dst, size_t dlen, time_t *when) { char buf[CTIME_BUFSIZ]; - ctime_r(when, buf); + if (!ctime_r(when, buf)) { + ret = -1; + break; + } snprintf(dst, dlen, "%s", buf); ret = rtrim_whitespace((unsigned char *) dst); break;