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

Marc-Antoine Perennou Marc-Antoine at Perennou.com
Wed Nov 6 20:48:58 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 9543ae3..0fd9aa1 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -3567,15 +3567,20 @@ _public_ int sd_bus_message_read_array(sd_bus_message *m,
         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