* [PATCH] tcp_vu: Fix assert/error-check order in tcp_vu_sock_recv()
@ 2026-11-09 22:13 Jon Maloy
0 siblings, 0 replies; only message in thread
From: Jon Maloy @ 2026-11-09 22:13 UTC (permalink / raw)
To: sbrivio, david, jmaloy, passt-dev
iov_tail_clone() returns a ssize_t. However, the assert comparing
it against (ARRAY_SIZE(iov_msg) - j), which yields size_t, comes
before the negative-value check. Hence, when iov_tail_clone() fails
and returns -1, the signed-to-unsigned promotion turns -1 into
SIZE_MAX, and causes the assert to fire.
We fix this by moving the error check before the assert, while casting
the counter and the index inside the assert to size_t.
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
tcp_vu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tcp_vu.c b/tcp_vu.c
index 868a35b9..c052d8e2 100644
--- a/tcp_vu.c
+++ b/tcp_vu.c
@@ -291,9 +291,9 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq,
cnt = iov_tail_clone(&iov_msg[j], ARRAY_SIZE(iov_msg) - j,
&data);
- assert(cnt < ARRAY_SIZE(iov_msg) - j);
if (cnt < 0)
die("Missing entries in iov_msg");
+ assert((size_t)cnt < ARRAY_SIZE(iov_msg) - (size_t)j);
j += cnt;
}
--
2.52.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-09 22:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 22:13 [PATCH] tcp_vu: Fix assert/error-check order in tcp_vu_sock_recv() Jon Maloy
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).