diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-04-07 14:45:19 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-04-07 15:04:48 +0100 |
commit | d23cdacb0da95a177dc7708bd26f284af732e508 (patch) | |
tree | d5ff8373e75be9fd87a7f5a814734b3748ba2c3e /bus | |
parent | 0980e63aacf52201bdf913e706d8ea0accc22610 (diff) |
path_prefix: anchor matches at path-component boundaries, and give examples
It seems wrong that path_prefix="/foo" matches /foobar, and it isn't
difficult or expensive to check.
Diffstat (limited to 'bus')
-rw-r--r-- | bus/signals.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/bus/signals.c b/bus/signals.c index 0d18dc6f..59133344 100644 --- a/bus/signals.c +++ b/bus/signals.c @@ -1801,6 +1801,7 @@ match_rule_matches (BusMatchRule *rule, if (flags & BUS_MATCH_PATH_PREFIX) { const char *path; + int len; _dbus_assert (rule->path_prefix != NULL); @@ -1810,6 +1811,17 @@ match_rule_matches (BusMatchRule *rule, if (!str_has_prefix (path, rule->path_prefix)) return FALSE; + + len = strlen (rule->path_prefix); + + /* Check that the actual argument is within the expected + * namespace, rather than just starting with that string, + * by checking that the matched prefix either ends in a '/', + * or is followed by a '/' or the end of the path. + */ + if (rule->path_prefix[len - 1] != '/' && + path[len] != '\0' && path[len] != '/') + return FALSE; } if (flags & BUS_MATCH_ARGS) @@ -2736,12 +2748,12 @@ path_prefix_should_not_match_message_2[] = { static const char* path_prefix_should_match_message_3[] = { - "type='signal',path_prefix='/foo/TheObjectManager'", NULL }; static const char* path_prefix_should_not_match_message_3[] = { + "type='signal',path_prefix='/foo/TheObjectManager'", "type='signal',path_prefix='/foo/TheObjectManager/'", NULL }; |