Skip to contentSkip to conversation

libfdt: Fix use of uninitialized variable in fdt_get_path()

PATCH Applied David Gibson 2 participants 2 messages Aug 31, 2007

lore
Share & tools
lore
#0 lore raw

My recent implemenetation of fdt_get_path() had a bug - the while loop tested offset which was unitialized on the first iteration. Depending on code surrounding the call, this could cause fdt_get_path() to return incorrect results.

This patch corrects the problem by applying some more correct thinking to the loop condition.

libfdt/fdt_ro.c +1 -1
Index: dtc/libfdt/fdt_ro.c
===================================================================
@@ -302,7 +302,7 @@
 	buf[0] = '/';
 	p = 1;
 
-	while (offset < nodeoffset) {
+	while (nextoffset <= nodeoffset) {
 		offset = nextoffset;
 		tag = _fdt_next_tag(fdt, offset, &nextoffset);
 		switch (tag) {
Signature · 4 lines
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
Applied
#1 lore raw

So, like, the other day David Gibson mumbled:

Quoted 9 lines

My recent implemenetation of fdt_get_path() had a bug - the while loop tested offset which was unitialized on the first iteration. Depending on code surrounding the call, this could cause fdt_get_path() to return incorrect results.

This patch corrects the problem by applying some more correct thinking to the loop condition.

Applied.

Thanks,
jdl