From: David Herrmann Date: Wed, 15 Jul 2015 12:35:15 +0000 (+0200) Subject: sd-bus: fix object tree to be deeper than 2 levels X-Git-Tag: v226.4~1^2~208 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=6fec834165df2fd841e1132d60d5228db0d1c494 sd-bus: fix object tree to be deeper than 2 levels So right now our object-tree is limited to 2 levels at most ('/' and '/foo/...../bar'). We never link any intermediate levels, even though that was clearly the plan. Fix the bus_node_allocate() helper to actually link all intermediate nodes, too, not just the root node. This fixes a simple inverse ptr-diff bug. The downside of this fix is that we clearly never tested (nor used) the object tree in any way. The only reason that the introspection works is that our enumerators shortcut the object tree. Lets see whether that code actually works.. Thanks to: Nathaniel McCallum ..for reporting this. See #524 for an actual example code. --- diff --git a/src/libelogind/sd-bus/bus-objects.c b/src/libelogind/sd-bus/bus-objects.c index b3cc28ee9..cbdf6552f 100644 --- a/src/libelogind/sd-bus/bus-objects.c +++ b/src/libelogind/sd-bus/bus-objects.c @@ -1416,7 +1416,7 @@ static struct node *bus_node_allocate(sd_bus *bus, const char *path) { e = strrchr(path, '/'); assert(e); - p = strndupa(path, MAX(1, path - e)); + p = strndupa(path, MAX(1, e - path)); parent = bus_node_allocate(bus, p); if (!parent)