aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2026-02-24 15:14:39 +0000
committerMark Johnston <markj@FreeBSD.org>2026-02-24 15:14:39 +0000
commitd7d4da91de201841c57a6b8f89b450754b9b8696 (patch)
tree5977a292be46e64066ef592798f14ad28b406a46
parentf4f9054dc47b430872d38c7a75fea753c6fe796f (diff)
bhyve: Fix truncate_iov()
The implementation was simply wrong. It would always just return the first entry in the iovec, even if the requested length is larger than that first entry. Note, this function will be removed soon, see D53468. Reported by: Vinod p n <vinod272@gmail.com> Reviewed by: des, emaste, Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D55438
-rw-r--r--usr.sbin/bhyve/iov.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/usr.sbin/bhyve/iov.c b/usr.sbin/bhyve/iov.c
index 5ebc426227a6..2bad55267ff3 100644
--- a/usr.sbin/bhyve/iov.c
+++ b/usr.sbin/bhyve/iov.c
@@ -81,19 +81,14 @@ count_iov(const struct iovec *iov, int niov)
void
truncate_iov(struct iovec *iov, int *niov, size_t length)
{
- size_t done = 0;
int i;
- for (i = 0; i < *niov; i++) {
- size_t toseek = MIN(length - done, iov[i].iov_len);
- done += toseek;
-
- if (toseek <= iov[i].iov_len) {
- iov[i].iov_len = toseek;
- *niov = i + 1;
- return;
- }
+ for (i = 0; i < *niov && length > 0; i++) {
+ if (length < iov[i].iov_len)
+ iov[i].iov_len = length;
+ length -= iov[i].iov_len;
}
+ *niov = i;
}
ssize_t