diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-07 18:40:06 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-07 18:40:06 +0100 |
commit | 5e86fd7b982e2d87537d4386bd1c9684c1ee7c43 (patch) | |
tree | 048c41a8569664308bfb42014925aa047ccdc97c /src | |
parent | b8ecc741db537f684ad3f7948ed60947cfc9e723 (diff) |
bus: allow reading empty arrays with sd_bus_message_read_array()
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-bus/bus-message.c | 18 | ||||
-rw-r--r-- | src/libsystemd-bus/test-bus-marshal.c | 7 |
2 files changed, 19 insertions, 6 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c index 3f9baca806..428568dcc2 100644 --- a/src/libsystemd-bus/bus-message.c +++ b/src/libsystemd-bus/bus-message.c @@ -3585,12 +3585,18 @@ _public_ int sd_bus_message_read_array(sd_bus_message *m, c = message_get_container(m); sz = BUS_MESSAGE_BSWAP32(m, *c->array_size); - r = message_peek_body(m, &m->rindex, align, sz, &p); - if (r < 0) - goto fail; - if (r == 0) { - r = -EBADMSG; - goto fail; + if (sz == 0) + /* Zero length array, let's return some aligned + * pointer that is not NULL */ + p = (uint8_t*) NULL + align; + else { + r = message_peek_body(m, &m->rindex, align, sz, &p); + if (r < 0) + goto fail; + if (r == 0) { + r = -EBADMSG; + goto fail; + } } r = sd_bus_message_exit_container(m); diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c index 5e29a7b6a2..8f36a71d4b 100644 --- a/src/libsystemd-bus/test-bus-marshal.c +++ b/src/libsystemd-bus/test-bus-marshal.c @@ -92,6 +92,9 @@ int main(int argc, char *argv[]) { r = sd_bus_message_append_array(m, 'i', integer_array, sizeof(integer_array)); assert_se(r >= 0); + r = sd_bus_message_append_array(m, 'u', NULL, 0); + assert_se(r >= 0); + r = bus_message_seal(m, 4711); assert_se(r >= 0); @@ -210,6 +213,10 @@ int main(int argc, char *argv[]) { assert_se(sz == sizeof(integer_array)); assert_se(memcmp(integer_array, return_array, sz) == 0); + r = sd_bus_message_read_array(m, 'u', (const void**) &return_array, &sz); + assert_se(r > 0); + assert_se(sz == 0); + r = sd_bus_message_peek_type(m, NULL, NULL); assert_se(r == 0); |