git: 10ed5b90e46f - main - mfiutil: Handle truncation in mfi_next_learn_time
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 07 Jul 2025 17:23:01 UTC
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';
}