]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
iovec-util: add overflow check in iovec_total_size()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Apr 2026 22:21:38 +0000 (07:21 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 18 Apr 2026 22:33:20 +0000 (07:33 +0900)
Mostly theoretical. But for safety.

src/basic/iovec-util.c

index ec8af57e6424ff50d2765de03c8dd1eb6d8043ba..cd2c1a736e8286300a8a9ff24f36b01a184d4cd8 100644 (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;
 }