sd-bus: use INC_SAFE and assert for message_from_header allocation

Coverity flags ALIGN() as potentially returning SIZE_MAX and the
subsequent a += label_sz + 1 as overflowing. Assert ALIGN result
is not SIZE_MAX and use INC_SAFE for the addition.

CID#1548030

Follow-up for 55354d5930
This commit is contained in:
Luca Boccassi
2026-04-08 00:34:56 +01:00
parent aaab31d7a0
commit f0bb176ee1

View File

@@ -359,12 +359,12 @@ static int message_from_header(
/* Note that we are happy with unknown flags in the flags header! */
a = ALIGN(sizeof(sd_bus_message));
/* Silence static analyzers, ALIGN cannot overflow for sizeof() */
assert(a != SIZE_MAX);
if (label) {
label_sz = strlen(label);
/* Silence static analyzers */
assert(label_sz <= SIZE_MAX - ALIGN(sizeof(sd_bus_message)) - 1);
a += label_sz + 1;
assert_se(INC_SAFE(&a, label_sz + 1));
}
m = malloc0(a);