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

Lennart Poettering lennart at poettering.net
Thu Nov 7 09:41:39 PST 2013


On Thu, 07.11.13 13:48, Marc-Antoine Perennou (Marc-Antoine at Perennou.com) wrote:

Applied a similar patch that just makes use of *array_size to detect if
we are looking at an empty array. Also added a test case for this!

Thanks!

> ---
>  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);


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list