On Tue, Apr 18, 2017 at 12:08:18AM +0000, Tim Montague wrote: > When determining if to recurse into a node, get_node_by_path does not > check if the length of each node name is equal. If searching for > /foo/baz, this can result in recursing into /food because > strneq("foo", "food", 3) is true. > > Signed-off-by: Tim Montague <tmontague@xxxxxxx> Looks like I made the classic strncmp() blunder, how embarrassing. Fix looks good, but I could trouble you to add a testcase exercising this? > --- > livetree.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/livetree.c b/livetree.c > index 3673de0..aecd278 100644 > --- a/livetree.c > +++ b/livetree.c > @@ -478,7 +478,8 @@ struct node *get_node_by_path(struct node *tree, const char *path) > p = strchr(path, '/'); > > for_each_child(tree, child) { > - if (p && strneq(path, child->name, p-path)) > + if (p && (strlen(child->name) == p-path) && > + strneq(path, child->name, p-path)) > return get_node_by_path(child, p+1); > else if (!p && streq(path, child->name)) > return child; -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Attachment:
signature.asc
Description: PGP signature