Skip to content

Commit

Permalink
match: validate arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Gundersen <[email protected]>
  • Loading branch information
teg authored and David Herrmann committed Feb 21, 2018
1 parent 2f468c6 commit c354159
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/bus/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,26 @@ static int match_keys_assign(MatchKeys *keys, const char *key, size_t n_key, con
} else if (match_key_equal("sender", key, n_key)) {
if (keys->sender)
return MATCH_E_INVALID;
if (!dbus_validate_name(value, strlen(value)))
return MATCH_E_INVALID;
keys->sender = value;
} else if (match_key_equal("destination", key, n_key)) {
if (keys->destination)
return MATCH_E_INVALID;
if (!dbus_validate_name(value, strlen(value)))
return MATCH_E_INVALID;
keys->destination = value;
} else if (match_key_equal("interface", key, n_key)) {
if (keys->filter.interface)
return MATCH_E_INVALID;
if (!dbus_validate_interface(value, strlen(value)))
return MATCH_E_INVALID;
keys->filter.interface = value;
} else if (match_key_equal("member", key, n_key)) {
if (keys->filter.member)
return MATCH_E_INVALID;
if (!dbus_validate_member(value, strlen(value)))
return MATCH_E_INVALID;
keys->filter.member = value;
} else if (match_key_equal("path", key, n_key)) {
if (keys->filter.path || keys->path_namespace)
Expand All @@ -65,6 +73,8 @@ static int match_keys_assign(MatchKeys *keys, const char *key, size_t n_key, con
} else if (match_key_equal("arg0namespace", key, n_key)) {
if (keys->arg0namespace || keys->filter.args[0] || keys->filter.argpaths[0])
return MATCH_E_INVALID;
if (!dbus_validate_namespace(value, strlen(value)))
return MATCH_E_INVALID;
keys->arg0namespace = value;
} else if (n_key >= strlen("arg") && match_key_equal("arg", key, strlen("arg"))) {
unsigned int i = 0;
Expand Down Expand Up @@ -303,7 +313,6 @@ static bool match_keys_match_filter(MatchKeys *keys, MatchFilter *filter) {
if (keys->path_namespace && !match_string_prefix(filter->path, keys->path_namespace, '/', false))
return false;

/* XXX: verify that arg0 is a (potentially single-label) bus name */
if (keys->arg0namespace && !match_string_prefix(filter->args[0], keys->arg0namespace, '.', false))
return false;

Expand Down
6 changes: 0 additions & 6 deletions src/bus/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,6 @@ static int peer_link_match(Peer *peer, MatchRule *rule, bool monitor) {
}
case ADDRESS_TYPE_NAME:
case ADDRESS_TYPE_OTHER: {
/*
* XXX: dbus-daemon rejects any match on invalid names.
* However, we cannot do this here as our caller
* does not expect this. This needs some further
* restructuring.
*/
_c_cleanup_(name_unrefp) Name *name = NULL;

r = name_registry_ref_name(&peer->bus->names, &name, rule->keys.sender);
Expand Down

0 comments on commit c354159

Please sign in to comment.