]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: assert ALIGN result in sd_bus_message_new
authorLuca Boccassi <luca.boccassi@gmail.com>
Tue, 7 Apr 2026 23:40:01 +0000 (00:40 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 8 Apr 2026 00:28:50 +0000 (01:28 +0100)
Coverity flags ALIGN(sizeof(sd_bus_message)) as potentially
returning SIZE_MAX, making the subsequent + sizeof(BusMessageHeader)
overflow. Store the ALIGN result in a local and assert it is not
SIZE_MAX.

CID#1548031

Follow-up for 4f5b28b72c7ff78c7eabcce7ad4f0eaebfd5545d

src/libsystemd/sd-bus/bus-message.c

index f66b2fa3e22648c7a5a2bd03ed23b8e487e80301..358fb3ca756dd7b0fbb75e5e1c66e1a2c394d541 100644 (file)
@@ -464,8 +464,8 @@ _public_ int sd_bus_message_new(
         /* Creation of messages with _SD_BUS_MESSAGE_TYPE_INVALID is allowed. */
         assert_return(type < _SD_BUS_MESSAGE_TYPE_MAX, -EINVAL);
 
-        /* Silence static analyzers */
-        assert_cc(sizeof(sd_bus_message) + sizeof(void*) + sizeof(BusMessageHeader) <= SIZE_MAX);
+        /* Silence static analyzers, ALIGN cannot overflow for sizeof() */
+        assert(ALIGN(sizeof(sd_bus_message)) != SIZE_MAX);
         sd_bus_message *t = malloc0(ALIGN(sizeof(sd_bus_message)) + sizeof(BusMessageHeader));
         if (!t)
                 return -ENOMEM;