Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Jul 2025 17:23:01 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 10ed5b90e46f - main - mfiutil: Handle truncation in mfi_next_learn_time
Message-ID:  <202507071723.567HN1uk080628@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=10ed5b90e46f5df329f511c08bd55458f95f1b6c

commit 10ed5b90e46f5df329f511c08bd55458f95f1b6c
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-07-07 16:37:09 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-07-07 16:37:09 +0000

    mfiutil: Handle truncation in mfi_next_learn_time
    
    Only trim the trailing newline if the output from ctime() was not
    truncated.  To simplify the code, use strlcpy() instead of snprintf()
    since strlcpy() can't fail with a negative size (and the previous code
    probably didn't handle those errors properly given the int -> size_t
    conversion).
    
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D50882
---
 usr.sbin/mfiutil/mfi_bbu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/mfiutil/mfi_bbu.c b/usr.sbin/mfiutil/mfi_bbu.c
index aa685e438453..3e78e791dfc2 100644
--- a/usr.sbin/mfiutil/mfi_bbu.c
+++ b/usr.sbin/mfiutil/mfi_bbu.c
@@ -71,8 +71,8 @@ mfi_next_learn_time(uint32_t next_learn_time, char *buf, size_t sz)
 	tm.tm_year = 100;
 	basetime = timegm(&tm);
 	basetime += (time_t)next_learn_time;
-	len = snprintf(buf, sz, "%s", ctime(&basetime));
-	if (len > 0)
+	len = strlcpy(buf, ctime(&basetime), sz);
+	if (len < sz)
 		/* Get rid of the newline added by ctime(3). */
 		buf[len - 1] = '\0';
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202507071723.567HN1uk080628>