[PATCH] Fix get_node_by_path string equality check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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>
---
 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;
-- 
2.7.4
��.n��������+%������w��{.n����z�{��z��^n�r������&��z�ޗ�zf���h���~����������_��+v���)ߣ�

[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux