Date: Wed, 22 Oct 2025 12:52:38 GMT From: Mark Johnston <markj@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: c47f9af4771b - stable/15 - libnv: Fix a length check in nvpair_unpack_string_array() Message-ID: <202510221252.59MCqc6l096167@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/15 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c47f9af4771bc7de2ebed4c91628c1f9a7f86a2c commit c47f9af4771bc7de2ebed4c91628c1f9a7f86a2c Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2025-10-15 20:15:08 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2025-10-22 12:51:59 +0000 libnv: Fix a length check in nvpair_unpack_string_array() A string array is represented by a set of nul-terminated strings concatenated together. For each string, we check to see if there's a nul terminator at the end, taking care to avoid going past the end of the buffer. However, the code fails to handle the possibility that size == 0 at the end of an iteration, leading to underflow. Fix the length check. Reported by: Ilja van Sprundel <ivansprundel@ioactive.com> Reviewed by: emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53069 (cherry picked from commit 937693fc9e4ff4045cc674a14902f0d53e84ec98) --- sys/contrib/libnv/bsd_nvpair.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/contrib/libnv/bsd_nvpair.c b/sys/contrib/libnv/bsd_nvpair.c index c73bc2189121..b884dd260b84 100644 --- a/sys/contrib/libnv/bsd_nvpair.c +++ b/sys/contrib/libnv/bsd_nvpair.c @@ -985,13 +985,13 @@ nvpair_unpack_string_array(bool isbe __unused, nvpair_t *nvp, size = nvp->nvp_datasize; tmp = (const char *)ptr; for (ii = 0; ii < nvp->nvp_nitems; ii++) { - len = strnlen(tmp, size - 1) + 1; - size -= len; - if (tmp[len - 1] != '\0') { + if (size <= 0) { ERRNO_SET(EINVAL); return (NULL); } - if (size < 0) { + len = strnlen(tmp, size - 1) + 1; + size -= len; + if (tmp[len - 1] != '\0') { ERRNO_SET(EINVAL); return (NULL); }help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202510221252.59MCqc6l096167>
