From f0bb176ee1c3d9f1084af271359e0ae51eb03d91 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 8 Apr 2026 00:34:56 +0100 Subject: [PATCH] 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 55354d5930fd0b7952d649d9ad5a850279fc73e1 --- src/libsystemd/sd-bus/bus-message.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 507c5d7ff40..f66b2fa3e22 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -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);