[systemd-devel] [PATCH 1/3] bus: allow reading empty arrays

Marc-Antoine Perennou Marc-Antoine at Perennou.com
Wed Nov 6 00:59:20 PST 2013


---
 src/libsystemd-bus/bus-message.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 437f6df..698c7c4 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -3549,15 +3549,20 @@ int sd_bus_message_read_array(sd_bus_message *m, char type, const void **ptr, si
         if (r <= 0)
                 return r;
 
-        c = message_get_container(m);
-        sz = BUS_MESSAGE_BSWAP32(m, *c->array_size);
+        if (message_end_of_array(m, m->rindex)) {
+                p = NULL;
+                sz = 0;
+        } else {
+                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;
+                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);
-- 
1.8.4.2



More information about the systemd-devel mailing list