Skip to content

Commit

Permalink
dtc: Fix NULL pointer use in dtlabel + dtref case
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
bebarino authored and dgibson committed Jan 30, 2017
1 parent 43eb551 commit 3b9c970
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dtc-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ dtc_tests () {
run_test dtbs_equal_ordered multilabel.test.dtb multilabel_merge.test.dtb
run_dtc_test -I dts -O dtb -o dtc_tree1_merge_path.test.dtb test_tree1_merge_path.dts
tree1_tests dtc_tree1_merge_path.test.dtb test_tree1.dtb
run_wrap_error_test $DTC -I dts -O dtb -o /dev/null test_label_ref.dts

# Check prop/node delete functionality
run_dtc_test -I dts -O dtb -o dtc_tree1_delete.test.dtb test_tree1_delete.dts
Expand Down
9 changes: 9 additions & 0 deletions tests/test_label_ref.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/dts-v1/;

/ {

};

label: &handle {

};

0 comments on commit 3b9c970

Please sign in to comment.