iovec-util: add overflow check in iovec_total_size()

Mostly theoretical. But for safety.
This commit is contained in:
Yu Watanabe
2026-04-19 07:33:20 +09:00
parent 16f5a2992d
commit 9628b31186
+4 -1
View File
@@ -21,8 +21,11 @@ size_t iovec_total_size(const struct iovec *iovec, size_t n) {
assert(iovec || n == 0);
FOREACH_ARRAY(j, iovec, n)
FOREACH_ARRAY(j, iovec, n) {
if (j->iov_len > SIZE_MAX - sum)
return SIZE_MAX; /* Indicate overflow. */
sum += j->iov_len;
}
return sum;
}