summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/bus-message.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-29 13:34:16 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-29 13:34:55 +0100
commit5461f53f186d4253c690df8d1ae06710e0d17585 (patch)
tree6ac0456e27feb5402e8e55b1b69431c8de7c2672 /src/libsystemd-bus/bus-message.c
parent03930e48636e86ad84946253ca2bf4f91deeb645 (diff)
bus: when turning a buffer into a sd_bus_message avoid creating zero-length parts
Diffstat (limited to 'src/libsystemd-bus/bus-message.c')
-rw-r--r--src/libsystemd-bus/bus-message.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index dd058e72c4..920488dae7 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -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;