[Pdbg] [PATCH] libpdbg: Don't dereference device tree root NULL targets

Cyril Bur cyrilbur at gmail.com
Tue Feb 20 16:57:31 AEDT 2018


It seems that the root of the device tree doesn't have a target
associated with it. This makes sense, however, pdbg_get_u64_property()
walks up the tree trying to find a given property and if it gets to the
root, the code will dereference NULL.

Make pdbg_get_u64_property() more robust.

Signed-off-by: Cyril Bur <cyrilbur at gmail.com>
---
That is how I caught the problem, but I figure it might be worse, what
if there isn't a target to a node for some other reason, lower down in
the tree... Thats why I went with this and not putting the check in the
condition of the loop.

Looking around at other functions in libpdbg.c I feel like there are
bigger problems.

I also contemplated making fake pdbg_targets that just had a pointer
back to the dt_node...

Thoughts?

---
 libpdbg/libpdbg.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c
index 6194048..2d6c7cc 100644
--- a/libpdbg/libpdbg.c
+++ b/libpdbg/libpdbg.c
@@ -191,6 +191,10 @@ int pdbg_get_u64_property(struct pdbg_target *target, const char *name, uint64_t
 	struct dt_node *dn;
 
 	for (dn = target->dn; dn; dn = dn->parent) {
+		/* This node doesn't have a target, skip it */
+		if (!dn->target)
+			continue;
+
 		if (!pdbg_get_target_u64_property(dn->target, name, val))
 			return 0;
 	}
-- 
2.16.2



More information about the Pdbg mailing list