sd-bus: add asserts for rbuffer_size accumulation bounds

Coverity flags rbuffer_size += k as a potential overflow, but k is
always bounded by the iov size (which is the difference between the
allocated buffer and current rbuffer_size). Add asserts to make this
invariant explicit.

CID#1548044
CID#1548071

Follow-up for a7e3212d89
This commit is contained in:
Luca Boccassi
2026-03-28 20:09:40 +00:00
parent 1b7d2fa978
commit c34169e9d3
+4
View File
@@ -676,6 +676,8 @@ static int bus_socket_read_auth(sd_bus *b) {
return -ECONNRESET;
}
/* Silence static analyzers, k is bounded by iov size: n - rbuffer_size */
assert((size_t) k <= n - b->rbuffer_size);
b->rbuffer_size += k;
if (handle_cmsg) {
@@ -1453,6 +1455,8 @@ int bus_socket_read_message(sd_bus *bus) {
return -EXFULL;
}
/* Silence static analyzers, k is bounded by iov size: need - rbuffer_size */
assert((size_t) k <= need - bus->rbuffer_size);
bus->rbuffer_size += k;
if (handle_cmsg) {