chiark / gitweb /
bus: when turning a buffer into a sd_bus_message avoid creating zero-length parts
authorLennart Poettering <lennart@poettering.net>
Fri, 29 Nov 2013 12:34:16 +0000 (13:34 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 29 Nov 2013 12:34:55 +0000 (13:34 +0100)
src/libsystemd-bus/bus-message.c

index dd058e7..920488d 100644 (file)
@@ -385,6 +385,7 @@ int bus_message_from_malloc(
                 sd_bus_message **ret) {
 
         sd_bus_message *m;
+        size_t sz;
         int r;
 
         r = bus_message_from_header(bus, buffer, length, fds, n_fds, ucred, label, 0, &m);
@@ -396,11 +397,14 @@ int bus_message_from_malloc(
                 goto fail;
         }
 
-        m->n_body_parts = 1;
-        m->body.data = (uint8_t*) buffer + sizeof(struct bus_header) + ALIGN8(BUS_MESSAGE_FIELDS_SIZE(m));
-        m->body.size = length - sizeof(struct bus_header) - ALIGN8(BUS_MESSAGE_FIELDS_SIZE(m));
-        m->body.sealed = true;
-        m->body.memfd = -1;
+        sz = length - sizeof(struct bus_header) - ALIGN8(BUS_MESSAGE_FIELDS_SIZE(m));
+        if (sz > 0) {
+                m->n_body_parts = 1;
+                m->body.data = (uint8_t*) buffer + sizeof(struct bus_header) + ALIGN8(BUS_MESSAGE_FIELDS_SIZE(m));
+                m->body.size = sz;
+                m->body.sealed = true;
+                m->body.memfd = -1;
+        }
 
         m->n_iovec = 1;
         m->iovec = m->iovec_fixed;