From dfcdee3fb01dde9227dfe007989caae5bd28e1c8 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 29 Jan 2018 15:29:31 +0100 Subject: [PATCH] message/metadata: remember the number of parsed arg{,path}X Use the information to cap the iterations through the array. Signed-off-by: Tom Gundersen --- src/bus/driver.c | 2 +- src/bus/peer.c | 2 +- src/dbus/message.c | 1 + src/dbus/message.h | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bus/driver.c b/src/bus/driver.c index 1fd08805..373172e2 100644 --- a/src/bus/driver.c +++ b/src/bus/driver.c @@ -329,7 +329,7 @@ static int driver_monitor(Bus *bus, Peer *sender, Message *message) { filter.member = message->metadata.fields.member, filter.path = message->metadata.fields.path; - for (size_t i = 0; i < 64; ++i) { + for (size_t i = 0; i < message->metadata.n_args; ++i) { if (message->metadata.args[i].element == 's') { filter.args[i] = message->metadata.args[i].value; filter.argpaths[i] = message->metadata.args[i].value; diff --git a/src/bus/peer.c b/src/bus/peer.c index cdd7aaa7..d9161660 100644 --- a/src/bus/peer.c +++ b/src/bus/peer.c @@ -773,7 +773,7 @@ int peer_broadcast(PolicySnapshot *sender_policy, NameSet *sender_names, MatchRe filter->member = message->metadata.fields.member, filter->path = message->metadata.fields.path; - for (size_t i = 0; i < 64; ++i) { + for (size_t i = 0; i < message->metadata.n_args; ++i) { if (message->metadata.args[i].element == 's') { filter->args[i] = message->metadata.args[i].value; filter->argpaths[i] = message->metadata.args[i].value; diff --git a/src/dbus/message.c b/src/dbus/message.c index 59b81078..3fd23a64 100644 --- a/src/dbus/message.c +++ b/src/dbus/message.c @@ -385,6 +385,7 @@ static int message_parse_body(Message *message, MessageMetadata *metadata) { if (i < C_ARRAY_SIZE(metadata->args)) { metadata->args[i].element = t->element; c_dvar_read(&v, (char[2]){ t->element, 0 }, &metadata->args[i].value); + metadata->n_args = i + 1; break; } diff --git a/src/dbus/message.h b/src/dbus/message.h index cc6cd60e..4125334b 100644 --- a/src/dbus/message.h +++ b/src/dbus/message.h @@ -56,6 +56,7 @@ struct MessageMetadata { char element; const void *value; } args[64]; + size_t n_args; }; struct Message {