[PATCH] dtc: Fix NULL pointer use in dtlabel + dtref case

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



If we have a construct like this:

	label: &handle {
		...
	};

Running dtc on it will cause a segfault, because we use 'target'
when it could be NULL. Move the add_label() call into the if
statement to fix this potentially bad use of a NULL pointer.

Signed-off-by: Stephen Boyd <stephen.boyd@xxxxxxxxxx>
---
 dtc-parser.y | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/dtc-parser.y b/dtc-parser.y
index b2fd4d155839..ca3f5003427c 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -171,10 +171,10 @@ devicetree:
 		{
 			struct node *target = get_node_by_ref($1, $3);
 
-			add_label(&target->labels, $2);
-			if (target)
+			if (target) {
+				add_label(&target->labels, $2);
 				merge_nodes(target, $4);
-			else
+			} else
 				ERROR(&@3, "Label or path %s not found", $3);
 			$$ = $1;
 		}
-- 
2.10.0.297.gf6727b0

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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