sd-bus: assert ALIGN8 result is not SIZE_MAX

Coverity flags sizeof(BusMessageHeader) + ALIGN8(m->fields_size)
as overflowing because ALIGN_TO can return SIZE_MAX as an overflow
sentinel. Assert that the aligned value is not SIZE_MAX to prove
the addition is safe.

CID#1548023
CID#1548046

Follow-up for 2ac7c17f9d
This commit is contained in:
Luca Boccassi
2026-04-08 00:11:01 +01:00
parent 8fa088b886
commit e60937b585

View File

@@ -153,7 +153,8 @@ static inline uint64_t BUS_MESSAGE_COOKIE(sd_bus_message *m) {
}
static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) {
/* Silence static analyzers */
/* Silence static analyzers, fields_size is validated at message creation */
assert(ALIGN8(m->fields_size) != SIZE_MAX);
assert(ALIGN8(m->fields_size) <= SIZE_MAX - sizeof(BusMessageHeader));
assert(m->body_size <= SIZE_MAX - sizeof(BusMessageHeader) - ALIGN8(m->fields_size));
return
@@ -163,7 +164,8 @@ static inline size_t BUS_MESSAGE_SIZE(sd_bus_message *m) {
}
static inline size_t BUS_MESSAGE_BODY_BEGIN(sd_bus_message *m) {
/* Silence static analyzers */
/* Silence static analyzers, fields_size is validated at message creation */
assert(ALIGN8(m->fields_size) != SIZE_MAX);
assert(ALIGN8(m->fields_size) <= SIZE_MAX - sizeof(BusMessageHeader));
return
sizeof(BusMessageHeader) +