From 01f3e462900bbd6b9cfe5aa27f81c8847dca89d4 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 30 Mar 2014 13:50:23 +0200 Subject: command: fix access to "metadata/list" property The function tag_property() in command.c passed a key action with empty path to m_property_read_list. This is normally not valid, because key actions are supposed to access sub-paths. But it's kind of inconvenient to check for this case in tag_property(). So make it valid by providing a m_property_unkey() function, which turns a key access to "" into a top-level action. --- options/m_property.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'options') diff --git a/options/m_property.c b/options/m_property.c index d235c27c95..23d328a0f9 100644 --- a/options/m_property.c +++ b/options/m_property.c @@ -246,6 +246,19 @@ bool m_property_split_path(const char *path, bstr *prefix, char **rem) } } +// If *action is M_PROPERTY_KEY_ACTION, but the associated path is "", then +// make this into a top-level action. +static void m_property_unkey(int *action, void **arg) +{ + if (*action == M_PROPERTY_KEY_ACTION) { + struct m_property_action_arg *ka = *arg; + if (!ka->key[0]) { + *action = ka->action; + *arg = ka->arg; + } + } +} + static int m_property_do_bstr(const m_option_t *prop_list, bstr name, int action, void *arg, void *ctx) { @@ -524,6 +537,7 @@ int m_property_read_sub(const struct m_sub_property *props, int action, void *ar int m_property_read_list(int action, void *arg, int count, m_get_item_cb get_item, void *ctx) { + m_property_unkey(&action, &arg); switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; -- cgit v1.2.3