From da3d2666728ed21707bd66182c4077f4adcd61aa Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Tue, 1 Nov 2022 16:58:17 -0400 Subject: [PATCH] FreeBSD: Fix regression from kmem_scnprintf() in libzfs kmem_scnprintf() is only available in libzpool. Recent buildbot issues with showing FreeBSD results kept us from seeing this before 97143b9d314d54409244f3995576d8cc8c1ebf0a was merged. The code has been changed to sanitize the output from `kmem_scnprintf()`. Reviewed-by: Allan Jude Reviewed-by: Brian Behlendorf Signed-off-by: Richard Yao Closes #14111 --- lib/libzfs/os/freebsd/libzfs_compat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libzfs/os/freebsd/libzfs_compat.c b/lib/libzfs/os/freebsd/libzfs_compat.c index 5e280cbae9..d1c1fea7fb 100644 --- a/lib/libzfs/os/freebsd/libzfs_compat.c +++ b/lib/libzfs/os/freebsd/libzfs_compat.c @@ -202,8 +202,10 @@ libzfs_error_init(int error) size_t msglen = sizeof (errbuf); if (modfind("zfs") < 0) { - size_t len = kmem_scnprintf(msg, msglen, dgettext(TEXT_DOMAIN, + size_t len = snprintf(msg, msglen, dgettext(TEXT_DOMAIN, "Failed to load %s module: "), ZFS_KMOD); + if (len >= msglen) + len = msglen - 1; msg += len; msglen -= len; }